[Scummvm-cvs-logs] CVS: scummvm/scumm/imuse_digi dimuse.cpp,1.53,1.54 dimuse.h,1.34,1.35

Pawel Kolodziejski aquadran at users.sourceforge.net
Sat Mar 27 12:38:03 CET 2004


Update of /cvsroot/scummvm/scummvm/scumm/imuse_digi
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5375/scumm/imuse_digi

Modified Files:
	dimuse.cpp dimuse.h 
Log Message:
implemented priorites for imuse sounds

Index: dimuse.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/imuse_digi/dimuse.cpp,v
retrieving revision 1.53
retrieving revision 1.54
diff -u -d -r1.53 -r1.54
--- dimuse.cpp	27 Mar 2004 18:12:18 -0000	1.53
+++ dimuse.cpp	27 Mar 2004 20:26:25 -0000	1.54
@@ -226,10 +226,46 @@
 	_track[track].regionOffset = 0;
 }
 
-void IMuseDigital::startSound(int soundId, const char *soundName, int soundType, int soundGroup, AudioStream *input, int hookId, int volume) {
+void IMuseDigital::startSound(int soundId, const char *soundName, int soundType, int soundGroup, AudioStream *input, int hookId, int volume, int priority) {
 	Common::StackLock lock(_mutex, g_system, "IMuseDigital::startSound()");
 	debug(5, "IMuseDigital::startSound(%d)", soundId);
 	int l;
+	int lower_priority = 127;
+	bool found_free = false;
+
+	for (l = 0; l < MAX_DIGITAL_TRACKS; l++) {
+		if (!_track[l].used && !_track[l].handle.isActive())
+			found_free = true;
+	}
+
+	if (!found_free) {
+		warning("IMuseDigital::startSound(): All slots are full");
+		for (l = 0; l < MAX_DIGITAL_TRACKS; l++) {
+			if (_track[l].used && _track[l].handle.isActive() &&
+					(lower_priority > _track[l].priority) && (!_track[l].stream2))
+				lower_priority = _track[l].priority;
+		}
+		if (lower_priority <= priority) {
+			int track_id = -1;
+			for (l = 0; l < MAX_DIGITAL_TRACKS; l++) {
+				if (_track[l].used && _track[l].handle.isActive() &&
+						(lower_priority == _track[l].priority) && (!_track[l].stream2)) {
+					track_id = l;
+				}
+			}
+			assert(track_id != -1);
+			_track[track_id].stream->finish();
+			_track[track_id].stream = NULL;
+			_vm->_mixer->stopHandle(_track[track_id].handle);
+			_sound->closeSound(_track[track_id].soundHandle);
+			_track[track_id].used = false;
+			assert(!_track[track_id].handle.isActive());
+			warning("IMuseDigital::startSound(): Removed sound %d from track %d", _track[track_id].soundId, track_id);
+		} else {
+			warning("IMuseDigital::startSound(): Priority sound too low");
+			return;
+		}
+	}
 
 	for (l = 0; l < MAX_DIGITAL_TRACKS; l++) {
 		if (!_track[l].used && !_track[l].handle.isActive()) {
@@ -243,6 +279,7 @@
 			_track[l].started = false;
 			_track[l].soundGroup = soundGroup;
 			_track[l].curHookId = hookId;
+			_track[l].priority = priority;
 			_track[l].curRegion = -1;
 			_track[l].dataOffset = 0;
 			_track[l].regionOffset = 0;
@@ -315,7 +352,9 @@
 			return;
 		}
 	}
-	warning("IMuseDigital::startSound(): All slots are full");
+
+	warning("it should not happen");
+	assert(0);
 }
 
 void IMuseDigital::stopSound(int soundId) {
@@ -332,6 +371,19 @@
 	}
 }
 
+void IMuseDigital::setPriority(int soundId, int priority) {
+	Common::StackLock lock(_mutex, g_system, "IMuseDigital::setPriority()");
+	debug(5, "IMuseDigital::setPrioritySound(%d, %d)", soundId, priority);
+
+	assert ((priority >= 0) && (priority <= 127));
+
+	for (int l = 0; l < MAX_DIGITAL_TRACKS; l++) {
+		if ((_track[l].soundId == soundId) && _track[l].used) {
+			_track[l].priority = priority;
+		}
+	}
+}
+
 void IMuseDigital::setVolume(int soundId, int volume) {
 	Common::StackLock lock(_mutex, g_system, "IMuseDigital::setVolume()");
 	debug(5, "IMuseDigital::setVolumeSound(%d, %d)", soundId, volume);
@@ -448,7 +500,8 @@
 		case 0x400: // set group volume
 			debug(5, "set group volume (0x400), soundId(%d), group volume(%d)", soundId, d);
 			break;
-		case 0x500: // set priority - could be ignored
+		case 0x500: // set priority
+			setPriority(soundId, d);
 			break;
 		case 0x600: // set volume
 			setVolume(soundId, d);

Index: dimuse.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/imuse_digi/dimuse.h,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -d -r1.34 -r1.35
--- dimuse.h	27 Mar 2004 17:03:42 -0000	1.34
+++ dimuse.h	27 Mar 2004 20:26:25 -0000	1.35
@@ -33,7 +33,7 @@
 
 namespace Scumm {
 
-#define MAX_DIGITAL_TRACKS 16
+#define MAX_DIGITAL_TRACKS 8
 
 struct imuseDigTable;
 struct imuseComiTable;
@@ -53,6 +53,7 @@
 		bool used;
 		bool toBeRemoved;
 		bool started;
+		int priority;
 		int32 regionOffset;
 		int32 trackOffset;
 		int32 dataOffset;
@@ -87,7 +88,7 @@
 	static void timer_handler(void *refConf);
 	void callback();
 	void switchToNextRegion(int track);
-	void startSound(int soundId, const char *soundName, int soundType, int soundGroup, AudioStream *input, int hookId, int volume);
+	void startSound(int soundId, const char *soundName, int soundType, int soundGroup, AudioStream *input, int hookId, int volume, int priority);
 
 	int32 getPosInMs(int soundId);
 	void getLipSync(int soundId, int syncId, int32 msPos, int32 &width, int32 &height);
@@ -113,15 +114,15 @@
 	virtual ~IMuseDigital();
 
 	void startVoice(int soundId, AudioStream *input)
-		{ debug(5, "startVoiceStream(%d)", soundId); startSound(soundId, NULL, 0, IMUSE_VOICE, input, 0, 127); }
+		{ debug(5, "startVoiceStream(%d)", soundId); startSound(soundId, NULL, 0, IMUSE_VOICE, input, 0, 127, 127); }
 	void startVoice(int soundId, const char *soundName)
-		{ debug(5, "startVoiceBundle(%s)", soundName); startSound(soundId, soundName, IMUSE_BUNDLE, IMUSE_VOICE, NULL, 0, 127); }
+		{ debug(5, "startVoiceBundle(%s)", soundName); startSound(soundId, soundName, IMUSE_BUNDLE, IMUSE_VOICE, NULL, 0, 127, 127); }
 	void startMusic(int soundId, int volume)
-		{ debug(5, "startMusicResource(%d)", soundId); startSound(soundId, NULL, IMUSE_RESOURCE, IMUSE_MUSIC, NULL, 0, volume); }
+		{ debug(5, "startMusicResource(%d)", soundId); startSound(soundId, NULL, IMUSE_RESOURCE, IMUSE_MUSIC, NULL, 0, volume, 126); }
 	void startMusic(const char *soundName, int soundId, int hookId, int volume)
-		{ debug(5, "startMusicBundle(%s)", soundName); startSound(soundId, soundName, IMUSE_BUNDLE, IMUSE_MUSIC, NULL, hookId, volume); }
-	void startSfx(int soundId)
-		{ debug(5, "startSfx(%d)", soundId); startSound(soundId, NULL, IMUSE_RESOURCE, IMUSE_SFX, NULL, 0, 127); }
+		{ debug(5, "startMusicBundle(%s)", soundName); startSound(soundId, soundName, IMUSE_BUNDLE, IMUSE_MUSIC, NULL, hookId, volume, 126); }
+	void startSfx(int soundId, int priority)
+		{ debug(5, "startSfx(%d)", soundId); startSound(soundId, NULL, IMUSE_RESOURCE, IMUSE_SFX, NULL, 0, 127, priority); }
 	void startSound(int soundId)
 		{ error("MusicEngine::startSound() Should be never called"); }
 	void resetState() {
@@ -132,6 +133,7 @@
 		_curSeqAtribPos = 0;
 	}
 
+	void setPriority(int soundId, int priority);
 	void setVolume(int soundId, int volume);
 	void setPan(int soundId, int pan);
 	void setFade(int soundId, int destVolume, int delay60HzTicks);





More information about the Scummvm-git-logs mailing list