[Scummvm-cvs-logs] CVS: scummvm/sword1 music.cpp,1.39,1.40

Robert Göffringmann lavosspawn at users.sourceforge.net
Sun Feb 20 11:06:52 CET 2005


Update of /cvsroot/scummvm/scummvm/sword1
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3899/sword1

Modified Files:
	music.cpp 
Log Message:
Changed mutex usage. 
It now unlocks the mutex while it's loading mp3/ogg/wave data in order to have the sound thread play normally. 
The ps2's cd/dvd drive is too slow to transfer the entire file within a few millisecs, so it made the sound skip.

Index: music.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword1/music.cpp,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -d -r1.39 -r1.40
--- music.cpp	28 Jan 2005 22:05:50 -0000	1.39
+++ music.cpp	20 Feb 2005 19:06:09 -0000	1.40
@@ -285,9 +285,9 @@
 }
 
 void Music::startMusic(int32 tuneId, int32 loopFlag) {
-	Common::StackLock lock(_mutex);
 	if (strlen(_tuneList[tuneId]) > 0) {
 		int newStream = 0;
+		_mutex.lock();
 		if (_handles[0].streaming() && _handles[1].streaming()) {
 			int streamToStop;
 			// Both streams playing - one must be forced to stop.
@@ -318,15 +318,25 @@
 			_handles[1].fadeDown();
 			newStream = 0;
 		}
+		delete _converter[newStream];
+		_converter[newStream] = NULL;
+		_mutex.unlock();
+
+		/* The handle will load the music file now. It can take a while, so unlock
+		   the mutex before, to have the soundthread playing normally. 
+		   As the corresponding _converter is NULL, the handle will be ignored by the playing thread */
 		if (_handles[newStream].play(_tuneList[tuneId], loopFlag != 0)) {
-			delete _converter[newStream];
+			_mutex.lock();
 			_converter[newStream] = makeRateConverter(_handles[newStream].getRate(), _mixer->getOutputRate(), _handles[newStream].isStereo(), false);
+			_mutex.unlock();
 		}
 	} else {
+		_mutex.lock();
 		if (_handles[0].streaming())
 			_handles[0].fadeDown();
 		if (_handles[1].streaming())
 			_handles[1].fadeDown();
+		_mutex.unlock();
 	}
 }
 





More information about the Scummvm-git-logs mailing list