[Scummvm-cvs-logs] CVS: scummvm/bs2/driver d_sound.cpp,1.60,1.61 d_sound.h,1.17,1.18

Torbj?rn Andersson eriktorbjorn at users.sourceforge.net
Thu Sep 25 23:27:07 CEST 2003


Update of /cvsroot/scummvm/scummvm/bs2/driver
In directory sc8-pr-cvs1:/tmp/cvs-serv27976

Modified Files:
	d_sound.cpp d_sound.h 
Log Message:
Ok, I'm stupid.

The initial sample is, indeed, two bytes, just like the rest of them, but
it really, really helps if you read it from the correct position in the
file.

After fixing that, it turned out that my changing of signedness of the
sample was also wrong. Funny how those two bugs almost cancelled each other
out. Almost.

I've made a few other changes as well, but they're just to clean things up
a bit. The credits music works for me, and I've played the game up to
arriving in Quaramonte, with no obvious music-related problems.


Index: d_sound.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/bs2/driver/d_sound.cpp,v
retrieving revision 1.60
retrieving revision 1.61
diff -u -d -r1.60 -r1.61
--- d_sound.cpp	25 Sep 2003 11:35:54 -0000	1.60
+++ d_sound.cpp	26 Sep 2003 06:26:18 -0000	1.61
@@ -181,26 +181,44 @@
 
 int16 MusicHandle::read() {
 	uint8 in;
-	uint16 delta, value;
+	uint16 delta;
 	int16 out;
 
 	if (!_streaming)
 		return 0;
 
+	if (_firstTime) {
+		_lastSample = fpMus.readUint16LE();
+		_filePos += 2;
+		_firstTime = false;
+		return _lastSample;
+	}
+
 	// Assume the file handle has been correctly positioned already.
 
 	in = fpMus.readByte();
 	delta = GetCompressedAmplitude(in) << GetCompressedShift(in);
 
 	if (GetCompressedSign(in))
-		value = _lastSample - delta;
+		out = _lastSample - delta;
 	else
-		value = _lastSample + delta;
+		out = _lastSample + delta;
 
 	_filePos++;
-	_lastSample = value;
+	_lastSample = out;
 
-	out = (int16) (value ^ 0x8000);
+	if (_looping) {
+		if (_filePos >= _fileEnd) {
+			_firstTime = true;
+			_filePos = _fileStart;
+		}
+	} else {
+		// Fade out at the end of the music. Is this really desirable
+		// behaviour?
+
+		if (_fileEnd - _filePos <= FADE_SAMPLES)
+			_fading = _fileEnd - _filePos;
+	}
 
 	if (_fading > 0) {
 		if (--_fading == 0) {
@@ -879,6 +897,7 @@
 }
 
 int32 Sword2Sound::StreamCompMusicFromLock(const char *filename, uint32 musicId, bool looping) {
+	uint32 len;
 	int32 primaryStream = -1;
 	int32 secondaryStream = -1;
 
@@ -934,60 +953,29 @@
 		music[secondaryStream]._fading = FADE_SAMPLES;
 
 	fpMus.seek((musicId + 1) * 8, SEEK_SET);
-	music[primaryStream]._filePos = fpMus.readUint32LE();
-	music[primaryStream]._fileEnd = fpMus.readUint32LE();
+	music[primaryStream]._fileStart = fpMus.readUint32LE();
+	len = fpMus.readUint32LE();
 
-	if (!music[primaryStream]._filePos || !music[primaryStream]._fileEnd)
+	if (!music[primaryStream]._fileStart || !len)
 		return RDERR_INVALIDID;
 
-	// Calculate the file position of the end of the music
-	music[primaryStream]._fileEnd += music[primaryStream]._filePos;
-
-	// We used to read two bytes for _lastSample, but doing that breaks
-	// some of the music, so I guess that was a bug. Maybe.
-
-	music[primaryStream]._lastSample = fpMus.readByte();
-	music[primaryStream]._filePos++;
+	music[primaryStream]._fileEnd = music[primaryStream]._fileStart + len;
+	music[primaryStream]._filePos = music[primaryStream]._fileStart;
 	music[primaryStream]._streaming = true;
+	music[primaryStream]._firstTime = true;
 
 	return RD_OK;
 }
 
 void Sword2Sound::UpdateCompSampleStreaming(int16 *data, uint len) {
-	uint32 i;
-
-	for (i = 0; i < MAXMUS; i++) {
+	for (int i = 0; i < MAXMUS; i++) {
 		if (!music[i]._streaming)
 			continue;
 
-		// Modify the volume according to the master volume and music
-		// mute state
-
 		byte volume = musicMuted ? 0 : musicVolTable[musicVol];
 
 		fpMus.seek(music[i]._filePos, SEEK_SET);
 		_converter->flow(music[i], data, len, volume, volume);
-
-		if (music[i].eos()) {
-			// End of the music so we need to start fading and
-			// start the music again
-
-			// FIXME: The original code faded the music here, but
-			// to do that we need to start before we reach the end
-			// of the file.
-			//
-			// On the other hand, do we want to fade out the end
-			// of the music?
-
-			// Fade the old music
-			// musFading[i] = -16;
-
-			// Loop if neccassary
-			if (music[i]._looping) {
-				music[i]._streaming = false;
-				StreamCompMusicFromLock(music[i]._fileName, music[i]._id, music[i]._looping);
-			}
-		}
 	}
 
 	// FIXME: We need to implement DipMusic()'s functionality, but since

Index: d_sound.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/bs2/driver/d_sound.h,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- d_sound.h	25 Sep 2003 10:02:52 -0000	1.17
+++ d_sound.h	26 Sep 2003 06:26:18 -0000	1.18
@@ -56,10 +56,12 @@
 public:
 	uint32 _id;
 	char _fileName[256];
+	bool _firstTime;
 	bool _streaming;
 	bool _paused;
 	bool _looping;
 	int32 _fading;
+	int32 _fileStart;
 	int32 _filePos;
 	int32 _fileEnd;
 	uint16 _lastSample;
@@ -70,8 +72,9 @@
 	int16 read();
 	bool eos() const;
 
-	MusicHandle() : MusicStream(), _streaming(false), _paused(false),
-			_looping(false), _fading(0), _filePos(0), _fileEnd(0),
+	MusicHandle() : MusicStream(), _firstTime(false), _streaming(false),
+			_paused(false), _looping(false), _fading(0),
+			_fileStart(0), _filePos(0), _fileEnd(0),
 			_lastSample(0) {
 		_fileName[0] = 0;
 	}





More information about the Scummvm-git-logs mailing list