[Scummvm-cvs-logs] SF.net SVN: scummvm:[45326] scummvm/trunk/engines/draci

spalek at users.sourceforge.net spalek at users.sourceforge.net
Thu Oct 22 08:21:40 CEST 2009


Revision: 45326
          http://scummvm.svn.sourceforge.net/scummvm/?rev=45326&view=rev
Author:   spalek
Date:     2009-10-22 06:21:39 +0000 (Thu, 22 Oct 2009)

Log Message:
-----------
Improved music handling:

- reading the volume from the configuration
- error handling of non-existent MIDI files
- pausing/resuming music

unfortunately, sometimes music stops playing or slows down, and my log
messages have so far not helped me to identify why

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

Modified: scummvm/trunk/engines/draci/draci.cpp
===================================================================
--- scummvm/trunk/engines/draci/draci.cpp	2009-10-22 06:05:34 UTC (rev 45325)
+++ scummvm/trunk/engines/draci/draci.cpp	2009-10-22 06:21:39 UTC (rev 45326)
@@ -366,7 +366,7 @@
 	Engine::syncSoundSettings();
 
 	_sound->setVolume();
-	_music->setVolume(ConfMan.getInt("music_volume"));
+	_music->syncVolume();
 }
 
 const char *DraciEngine::getSavegameFile(int saveGameIdx) {

Modified: scummvm/trunk/engines/draci/music.cpp
===================================================================
--- scummvm/trunk/engines/draci/music.cpp	2009-10-22 06:05:34 UTC (rev 45325)
+++ scummvm/trunk/engines/draci/music.cpp	2009-10-22 06:21:39 UTC (rev 45326)
@@ -23,8 +23,6 @@
  *
  */
 
-// FIXME: This code is taken from SAGA and needs more work (e.g. setVolume).
-
 // MIDI and digital music class
 
 #include "sound/audiostream.h"
@@ -38,7 +36,7 @@
 
 namespace Draci {
 
-MusicPlayer::MusicPlayer(MidiDriver *driver, const char *pathMask) : _parser(0), _driver(driver), _pathMask(pathMask), _looping(false), _isPlaying(false), _passThrough(false), _isGM(false) {
+MusicPlayer::MusicPlayer(MidiDriver *driver, const char *pathMask) : _parser(0), _driver(driver), _pathMask(pathMask), _looping(false), _isPlaying(false), _passThrough(false), _isGM(false), _track(0) {
 	memset(_channel, 0, sizeof(_channel));
 	_masterVolume = 0;
 	this->open();
@@ -67,7 +65,10 @@
 
 	for (int i = 0; i < 16; ++i) {
 		if (_channel[i]) {
-			_channel[i]->volume(_channelVolume[i] * _masterVolume / 255);
+			int newVolume = _channelVolume[i] * _masterVolume / 255;
+			debugC(3, kDraciSoundDebugLevel, "Music channel %d: volume %d->%d",
+				i, _channelVolume[i], newVolume);
+			_channel[i]->volume(newVolume);
 		}
 	}
 }
@@ -146,20 +147,25 @@
 }
 
 void MusicPlayer::playSMF(int track, bool loop) {
-	if (_isPlaying && track == _track)
+	if (_isPlaying && track == _track) {
+		debugC(2, kDraciSoundDebugLevel, "Already plaing track %d", track);
 		return;
+	}
 
 	stop();
 
 	_isGM = true;
 
-	debugC(2, kDraciSoundDebugLevel, "Playing track %d", track);
 
 	// Load MIDI resource data
 	Common::File musicFile;
 	char musicFileName[40];
 	sprintf(musicFileName, _pathMask.c_str(), track);
 	musicFile.open(musicFileName);
+	if (!musicFile.isOpen()) {
+		debugC(2, kDraciSoundDebugLevel, "Cannot open track %d", track);
+		return;
+	}
 	int midiMusicSize = musicFile.size();
 	delete _midiMusicData;
 	_midiMusicData = new byte[midiMusicSize];
@@ -175,17 +181,25 @@
 
 		_parser = parser;
 
-		setVolume(127);
+		syncVolume();
 
 		_looping = loop;
 		_isPlaying = true;
 		_track = track;
+		debugC(2, kDraciSoundDebugLevel, "Playing track %d", track);
+	} else {
+		debugC(2, kDraciSoundDebugLevel, "Cannot play track %d", track);
 	}
 }
 
 void MusicPlayer::stop() {
 	Common::StackLock lock(_mutex);
 
+	if (!_isPlaying)
+		return;
+
+	debugC(2, kDraciSoundDebugLevel, "Stopping track %d", _track);
+	_track = 0;
 	_isPlaying = false;
 	if (_parser) {
 		_parser->unloadMusic();
@@ -194,20 +208,29 @@
 }
 
 void MusicPlayer::pause() {
+	debugC(2, kDraciSoundDebugLevel, "Pausing track %d", _track);
 	setVolume(-1);
 	_isPlaying = false;
 }
 
 void MusicPlayer::resume() {
-	setVolume(127);
+	debugC(2, kDraciSoundDebugLevel, "Resuming track %d", _track);
+	syncVolume();
 	_isPlaying = true;
 }
 
+void MusicPlayer::syncVolume() {
+	int volume = ConfMan.getInt("music_volume");
+	debugC(2, kDraciSoundDebugLevel, "Syncing music volume to %d", volume);
+	setVolume(volume);
+}
+
 // TODO:
-// - volume support
+// + volume support
 // - bindings to GPL2 scripting
 // - load cmf.ins
 // - enable Adlib
-// - resuming after load
+// - resuming after configuration
+// + error handling
 
 } // End of namespace Draci

Modified: scummvm/trunk/engines/draci/music.h
===================================================================
--- scummvm/trunk/engines/draci/music.h	2009-10-22 06:05:34 UTC (rev 45325)
+++ scummvm/trunk/engines/draci/music.h	2009-10-22 06:21:39 UTC (rev 45326)
@@ -46,6 +46,7 @@
 
 	void setVolume(int volume);
 	int getVolume() { return _masterVolume; }
+	void syncVolume();
 
 	void setNativeMT32(bool b) { _nativeMT32 = b; }
 	bool hasNativeMT32() { return _nativeMT32; }


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