[Scummvm-cvs-logs] CVS: scummvm/sword2/driver d_sound.cpp,1.101,1.102

Torbj?rn Andersson eriktorbjorn at users.sourceforge.net
Wed Jan 14 00:07:06 CET 2004


Update of /cvsroot/scummvm/scummvm/sword2/driver
In directory sc8-pr-cvs1:/tmp/cvs-serv7550

Modified Files:
	d_sound.cpp 
Log Message:
Changed the music fading so that volume is increased when ABS(_fading)
grows larger, both when fading up or down. This fixes the problem where the
volume would "jump" when changing the fading "direction" of a stream.

Also changed the logic for deciding which music stream to stop if both
streams are playing and a third stream is started. Before it always tried
to pick the one that was fading down. Now it will pick the one with the
lowest volume, assuming that the more faded a stream is the lower its
volume.

Together, this should fix some abrupt music changes at the watchman's hut,
where it would sometimes start two music streams in rapid succession.


Index: d_sound.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/driver/d_sound.cpp,v
retrieving revision 1.101
retrieving revision 1.102
diff -u -d -r1.101 -r1.102
--- d_sound.cpp	12 Jan 2004 08:01:25 -0000	1.101
+++ d_sound.cpp	14 Jan 2004 08:06:56 -0000	1.102
@@ -141,7 +141,7 @@
 	if (_fading > 0)
 		_fading = -_fading;
 	else if (_fading == 0)
-		_fading = -FADE_SAMPLES;
+		_fading = -1;
 }
 
 int32 MusicHandle::play(const char *filename, uint32 musicId, bool looping) {
@@ -221,8 +221,10 @@
 				}
 				out = (out * _fading) / FADE_SAMPLES;
 			} else if (_fading < 0) {
-				_fading++;
-				out = (out * (FADE_SAMPLES + _fading)) / FADE_SAMPLES;
+				_fading--;
+				out = -(out * _fading) / FADE_SAMPLES;
+				if (_fading == -FADE_SAMPLES)
+					_fading = 0;
 			}
 		}
 
@@ -420,14 +422,27 @@
 	int32 primaryStream = -1;
 	int32 secondaryStream = -1;
 
-	// If both music streams are playing, that should mean one of them is
-	// fading out. Pick that one, and stop it completely.
+	// If both music streams are playing, one of them will have to go.
 
 	if (_music[0]._streaming && _music[1]._streaming) {
-		if (_music[0]._fading > 0)
+		if (_music[0]._fading == 0 && _music[1]._fading == 0) {
+			// None of them are fading. This shouldn't happen, so
+			// just pick one and be done with it.
 			primaryStream = 0;
-		else
+		} else if (_music[0]._fading != 0 && _music[1]._fading == 0) {
+			// Stream 0 is fading, so pick that one.
+			primaryStream = 0;
+		} else if (_music[0]._fading == 0 && _music[1]._fading > 0) {
+			// Stream 1 is fading, so pick that one.
 			primaryStream = 1;
+		} else {
+			// Both streams are fading. Pick the one that is
+			// closest to silent.
+			if (ABS(_music[0]._fading) < ABS(_music[1]._fading))
+				primaryStream = 0;
+			else
+				primaryStream = 1;
+		}
 
 		_music[primaryStream].stop();
 	}





More information about the Scummvm-git-logs mailing list