[Scummvm-cvs-logs] SF.net SVN: scummvm:[35116] scummvm/trunk/engines/groovie

eriktorbjorn at users.sourceforge.net eriktorbjorn at users.sourceforge.net
Tue Nov 18 20:29:51 CET 2008


Revision: 35116
          http://scummvm.svn.sourceforge.net/scummvm/?rev=35116&view=rev
Author:   eriktorbjorn
Date:     2008-11-18 19:29:51 +0000 (Tue, 18 Nov 2008)

Log Message:
-----------
Added a mutex to the Groovie MIDI player. Maybe that will fix the rare and
unpredictable crashes I've been seeing.

Modified Paths:
--------------
    scummvm/trunk/engines/groovie/music.cpp
    scummvm/trunk/engines/groovie/music.h

Modified: scummvm/trunk/engines/groovie/music.cpp
===================================================================
--- scummvm/trunk/engines/groovie/music.cpp	2008-11-18 17:48:19 UTC (rev 35115)
+++ scummvm/trunk/engines/groovie/music.cpp	2008-11-18 19:29:51 UTC (rev 35116)
@@ -37,7 +37,7 @@
 	// Create the driver
 	int driver = detectMusicDriver(MDT_MIDI | MDT_ADLIB | MDT_PREFER_MIDI);
 	_driver = createMidi(driver);
-	_driver->open();
+	this->open();
 
 	// Initialize the channel volumes
 	for (int i = 0; i < 0x10; i++) {
@@ -52,6 +52,10 @@
 }
 
 MusicPlayer::~MusicPlayer() {
+	_driver->setTimerCallback(NULL, NULL);
+
+	Common::StackLock lock(_mutex);
+
 	// Unload the parser
 	unload();
 	delete _midiParser;
@@ -62,18 +66,25 @@
 }
 
 void MusicPlayer::playSong(uint16 fileref) {
+	Common::StackLock lock(_mutex);
+
 	// Play the referenced file once
 	play(fileref, false);
 }
 
 void MusicPlayer::setBackgroundSong(uint16 fileref) {
+	Common::StackLock lock(_mutex);
+
 	_backgroundFileRef = fileref;
 }
 
 void MusicPlayer::setUserVolume(uint16 volume) {
+	Common::StackLock lock(_mutex);
+
 	// Save the new user volume
 	_userVolume = volume;
-	if (_userVolume > 0x100) _userVolume = 0x100;
+	if (_userVolume > 0x100)
+		_userVolume = 0x100;
 
 	// Apply it to all the channels
 	for (int i = 0; i < 0x10; i++) {
@@ -84,12 +95,15 @@
 }
 
 void MusicPlayer::setGameVolume(uint16 volume, uint16 time) {
+	Common::StackLock lock(_mutex);
+
 	//TODO: Implement volume fading
 	debugC(5, kGroovieDebugMIDI | kGroovieDebugAll, "setting game volume: %d, %d\n", volume, time);
 
 	// Save the new game volume
 	_gameVolume = volume;
-	if (_gameVolume > 100) _gameVolume = 100;
+	if (_gameVolume > 100)
+		_gameVolume = 100;
 
 	// Apply it to all the channels
 	for (int i = 0; i < 0x10; i++) {
@@ -159,6 +173,15 @@
 }
 
 int MusicPlayer::open() {
+	// Don't ever call open without first setting the output driver!
+	if (!_driver)
+		return 255;
+
+	int ret = _driver->open();
+	if (ret)
+		return ret;
+
+	_driver->setTimerCallback(this, &onTimer);
 	return 0;
 }
 
@@ -192,6 +215,14 @@
 	}
 }
 
+void MusicPlayer::onTimer(void *refCon) {
+	MusicPlayer *music = (MusicPlayer *)refCon;
+	Common::StackLock lock(music->_mutex);
+
+	// TODO: We really only need to call this while music is playing.
+	music->_midiParser->onTimer();
+}
+
 void MusicPlayer::setTimerCallback(void *timer_param, Common::TimerManager::TimerProc timer_proc) {
 	_driver->setTimerCallback(timer_param, timer_proc);
 }

Modified: scummvm/trunk/engines/groovie/music.h
===================================================================
--- scummvm/trunk/engines/groovie/music.h	2008-11-18 17:48:19 UTC (rev 35115)
+++ scummvm/trunk/engines/groovie/music.h	2008-11-18 19:29:51 UTC (rev 35116)
@@ -30,6 +30,7 @@
 
 #include "sound/mididrv.h"
 #include "sound/midiparser.h"
+#include "common/mutex.h"
 
 namespace Groovie {
 
@@ -62,12 +63,15 @@
 
 private:
 	GroovieEngine *_vm;
+	Common::Mutex _mutex;
 	byte *_data;
 	MidiParser *_midiParser;
 	MidiDriver *_driver;
 
 	uint16 _backgroundFileRef;
 
+	static void onTimer(void *data);
+
 	bool play(uint16 fileref, bool loop);
 	bool load(uint16 fileref);
 	void unload();


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list