diff options
author | Robert Špalek | 2009-10-22 06:21:39 +0000 |
---|---|---|
committer | Robert Špalek | 2009-10-22 06:21:39 +0000 |
commit | 3903be61e750ddee32350dc52c75a9f4893da475 (patch) | |
tree | 5306b82a51fb721c1a373cf2f80d6232fcb72cbe /engines | |
parent | 958bc7ba8116a5de1fc92c036c9d2fb1688a3d79 (diff) | |
download | scummvm-rg350-3903be61e750ddee32350dc52c75a9f4893da475.tar.gz scummvm-rg350-3903be61e750ddee32350dc52c75a9f4893da475.tar.bz2 scummvm-rg350-3903be61e750ddee32350dc52c75a9f4893da475.zip |
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
svn-id: r45326
Diffstat (limited to 'engines')
-rw-r--r-- | engines/draci/draci.cpp | 2 | ||||
-rw-r--r-- | engines/draci/music.cpp | 43 | ||||
-rw-r--r-- | engines/draci/music.h | 1 |
3 files changed, 35 insertions, 11 deletions
diff --git a/engines/draci/draci.cpp b/engines/draci/draci.cpp index 19732e7687..4b93e02ab6 100644 --- a/engines/draci/draci.cpp +++ b/engines/draci/draci.cpp @@ -366,7 +366,7 @@ void DraciEngine::syncSoundSettings() { Engine::syncSoundSettings(); _sound->setVolume(); - _music->setVolume(ConfMan.getInt("music_volume")); + _music->syncVolume(); } const char *DraciEngine::getSavegameFile(int saveGameIdx) { diff --git a/engines/draci/music.cpp b/engines/draci/music.cpp index b63c171974..a5694ae2c9 100644 --- a/engines/draci/music.cpp +++ b/engines/draci/music.cpp @@ -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 @@ void MusicPlayer::setVolume(int volume) { 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::onTimer(void *refCon) { } 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 @@ void MusicPlayer::playSMF(int track, bool loop) { _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::stop() { } 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 diff --git a/engines/draci/music.h b/engines/draci/music.h index bd8ffe6301..d56de17866 100644 --- a/engines/draci/music.h +++ b/engines/draci/music.h @@ -46,6 +46,7 @@ public: void setVolume(int volume); int getVolume() { return _masterVolume; } + void syncVolume(); void setNativeMT32(bool b) { _nativeMT32 = b; } bool hasNativeMT32() { return _nativeMT32; } |