[Scummvm-cvs-logs] SF.net SVN: scummvm:[39946] scummvm/branches/branch-0-13-0/engines/sword2/ music.cpp
eriktorbjorn at users.sourceforge.net
eriktorbjorn at users.sourceforge.net
Mon Apr 13 13:51:27 CEST 2009
Revision: 39946
http://scummvm.svn.sourceforge.net/scummvm/?rev=39946&view=rev
Author: eriktorbjorn
Date: 2009-04-13 11:51:27 +0000 (Mon, 13 Apr 2009)
Log Message:
-----------
Backported fix for bug #2614306 ("BS2: noise in music or speech"). I've played
through the entire game with the original sound files, without encountering the
bug, and I have at least tried a few things with compressed sound, so it should
be ok for 0.13.1.
Modified Paths:
--------------
scummvm/branches/branch-0-13-0/engines/sword2/music.cpp
Modified: scummvm/branches/branch-0-13-0/engines/sword2/music.cpp
===================================================================
--- scummvm/branches/branch-0-13-0/engines/sword2/music.cpp 2009-04-12 14:02:20 UTC (rev 39945)
+++ scummvm/branches/branch-0-13-0/engines/sword2/music.cpp 2009-04-13 11:51:27 UTC (rev 39946)
@@ -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) {
@@ -95,6 +128,7 @@
fh->file.open(filename);
fh->fileType = soundMode;
+
if (!fh->file.isOpen()) {
warning("BS2 getAudioStream: Failed opening file '%s'", filename);
return NULL;
@@ -147,27 +181,24 @@
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:
@@ -549,9 +580,8 @@
* @return RD_OK or an error code
*/
int32 Sound::streamCompMusic(uint32 musicId, bool loop) {
- //Common::StackLock lock(_mutex);
+ Common::StackLock lock(_mutex);
- _mutex.lock();
int cd = _vm->_resman->getCD();
if (loop)
@@ -607,7 +637,6 @@
// Don't start streaming if the volume is off.
if (isMusicMute()) {
- _mutex.unlock();
return RD_OK;
}
@@ -615,20 +644,15 @@
_music[secondary]->fadeDown();
SoundFileHandle *fh = (cd == 1) ? &_musicFile[0] : &_musicFile[1];
fh->inUse = true;
- _mutex.unlock();
MusicInputStream *tmp = new MusicInputStream(cd, fh, musicId, loop);
if (tmp->isReady()) {
- _mutex.lock();
_music[primary] = tmp;
fh->inUse = false;
- _mutex.unlock();
return RD_OK;
} else {
- _mutex.lock();
fh->inUse = false;
- _mutex.unlock();
delete tmp;
return RDERR_INVALIDFILENAME;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list