[Scummvm-cvs-logs] CVS: scummvm/simon midi.cpp,1.56,1.57 midi.h,1.21,1.22

Jamieson Christian jamieson630 at users.sourceforge.net
Sun Aug 10 22:26:02 CEST 2003


Update of /cvsroot/scummvm/scummvm/simon
In directory sc8-pr-cvs1:/tmp/cvs-serv16972/scummvm/simon

Modified Files:
	midi.cpp midi.h 
Log Message:
More music volume management fixes

Index: midi.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/simon/midi.cpp,v
retrieving revision 1.56
retrieving revision 1.57
diff -u -d -r1.56 -r1.57
--- midi.cpp	11 Aug 2003 04:33:17 -0000	1.56
+++ midi.cpp	11 Aug 2003 05:25:33 -0000	1.57
@@ -61,8 +61,8 @@
 	_enable_sfx = true;
 	_current = 0;
 
-	memset(_volumeTable, 127, sizeof(_volumeTable));
 	_masterVolume = 255;
+	resetVolumeTable();
 	_paused = false;
 
 	_currentTrack = 255;
@@ -104,12 +104,11 @@
 	if (!_current)
 		return;
 
-	byte volume;
-
+	byte channel = (byte) (b & 0x0F);
 	if ((b & 0xFFF0) == 0x07B0) {
 		// Adjust volume changes by master volume.
-		volume = (byte) ((b >> 16) & 0x7F);
-		_volumeTable [b & 0xF] = volume;
+		byte volume = (byte) ((b >> 16) & 0x7F);
+		_current->volume [channel] = volume;
 		volume = volume * _masterVolume / 255;
 		b = (b & 0xFF00FFFF) | (volume << 16);
 	} else if ((b & 0xF0) == 0xC0 && _map_mt32_to_gm) {
@@ -121,7 +120,6 @@
 			return;
 	}
 
-	byte channel = (byte) (b & 0x0F);
 	if (!_current->channel [channel])
 		_current->channel[channel] = (channel == 9) ? _driver->getPercussionChannel() : _driver->allocateChannel();
 	if (_current->channel [channel])
@@ -233,8 +231,12 @@
 	_paused = b;
 
 	_system->lock_mutex (_mutex);
-	for (int i = ARRAYSIZE (_volumeTable); i; --i)
-		_driver->send (((_paused ? 0 : (_volumeTable[i-1] * _masterVolume / 255)) << 16) | (7 << 8) | 0xB0 | i);
+	for (int i = 0; i < 16; ++i) {
+		if (_music.channel[i])
+			_music.channel[i]->volume (_paused ? 0 : (_music.volume[i] * _masterVolume / 255));
+		if (_sfx.channel[i])
+			_sfx.channel[i]->volume (_paused ? 0 : (_sfx.volume[i] * _masterVolume / 255));
+	}
 	_system->unlock_mutex (_mutex);
 }
 
@@ -246,14 +248,16 @@
 
 	if (_masterVolume == volume)
 		return;
-
 	_masterVolume = volume;
 
 	// Now tell all the channels this.
 	_system->lock_mutex (_mutex);
 	if (_driver && !_paused) {
-		for (int i = ARRAYSIZE (_volumeTable); i; --i) {
-			_driver->send (((_volumeTable[i-1] * _masterVolume / 255) << 16) | (7 << 8) | 0xB0 | i);
+		for (int i = 0; i < 16; ++i) {
+			if (_music.channel[i])
+				_music.channel[i]->volume (_music.volume[i] * _masterVolume / 255);
+			if (_sfx.channel[i])
+				_sfx.channel[i]->volume (_sfx.volume[i] * _masterVolume / 255);
 		}
 	}
 	_system->unlock_mutex (_mutex);
@@ -317,7 +321,7 @@
 	if (_driver) {
 		for (i = 0; i < 16; ++i) {
 			if (info.channel[i]) {
-				_driver->send (0x007BB0 | info.channel[i]->getNumber()); // All Notes Off
+				info.channel[i]->allNotesOff();
 				info.channel[i]->release();
 			}
 		}
@@ -325,6 +329,15 @@
 	info.clear();
 }
 
+void MidiPlayer::resetVolumeTable() {
+	int i;
+	for (i = 0; i < 16; ++i) {
+		_music.volume[i] = _sfx.volume[i] = 127;
+		if (_driver)
+			_driver->send (((_masterVolume >> 1) << 16) | 0x7B0 | i);
+	}
+}
+
 static int simon1_gmf_size[] = {
 	8900, 12166, 2848, 3442, 4034, 4508, 7064, 9730, 6014, 4742, 3138,
 	6570, 5384, 8909, 6457, 16321, 2742, 8968, 4804, 8442, 7717,
@@ -397,7 +410,7 @@
 
 	if (!sfx) {
 		_currentTrack = 255;
-		memset(_volumeTable, 127, sizeof(_volumeTable));
+		resetVolumeTable();
 	}
 	p->parser = parser; // That plugs the power cord into the wall
 	_system->unlock_mutex (_mutex);
@@ -456,7 +469,7 @@
 
 	if (!sfx) {
 		_currentTrack = 255;
-		memset(_volumeTable, 127, sizeof(_volumeTable));
+		resetVolumeTable();
 	}
 	_system->unlock_mutex (_mutex);
 }
@@ -505,7 +518,7 @@
 
 	if (!sfx) {
 		_currentTrack = 255;
-		memset(_volumeTable, 127, sizeof(_volumeTable));
+		resetVolumeTable();
 	}
 	p->parser = parser; // That plugs the power cord into the wall
 	_system->unlock_mutex (_mutex);
@@ -537,7 +550,7 @@
 
 	if (!sfx) {
 		_currentTrack = 255;
-		memset(_volumeTable, 127, sizeof(_volumeTable));
+		resetVolumeTable();
 	}
 	p->parser = parser; // That plugs the power cord into the wall
 	_system->unlock_mutex (_mutex);

Index: midi.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/simon/midi.h,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- midi.h	14 Jul 2003 08:29:17 -0000	1.21
+++ midi.h	11 Aug 2003 05:25:33 -0000	1.22
@@ -34,7 +34,9 @@
 	byte   num_songs;         // For Type 1 SMF resources
 	byte * songs[16];         // For Type 1 SMF resources
 	uint32 song_sizes[16];    // For Type 1 SMF resources
+
 	MidiChannel *channel[16]; // Dynamic remapping of channels to resolve conflicts
+	byte volume[16];          // Current channel volume
 
 	MusicInfo() { clear(); }
 	void clear() {
@@ -57,7 +59,6 @@
 	MusicInfo *_current; // Allows us to establish current context for operations.
 
 	// These are maintained for both music and SFX
-	byte _volumeTable[16]; // 0-127
 	byte _masterVolume;    // 0-255
 	bool _paused;
 
@@ -67,9 +68,11 @@
 	byte _queuedTrack;
 	bool _loopQueuedTrack;
 
+protected:
 	static void onTimer (void *data);
 	void clearConstructs();
 	void clearConstructs (MusicInfo &info);
+	void resetVolumeTable();
 
 public:
 	bool _enable_sfx;





More information about the Scummvm-git-logs mailing list