diff options
author | Max Horn | 2008-01-01 11:27:29 +0000 |
---|---|---|
committer | Max Horn | 2008-01-01 11:27:29 +0000 |
commit | 305f60e0dbefa3861f5ca3614a2b930aca8afc2c (patch) | |
tree | fe546c9f565ff4c9a999158e97a4e6af107a8d0f /engines/scumm/imuse_digi/dimuse_track.cpp | |
parent | a8d3967f63f51c77b8a934ec05b09803185afa12 (diff) | |
download | scummvm-rg350-305f60e0dbefa3861f5ca3614a2b930aca8afc2c.tar.gz scummvm-rg350-305f60e0dbefa3861f5ca3614a2b930aca8afc2c.tar.bz2 scummvm-rg350-305f60e0dbefa3861f5ca3614a2b930aca8afc2c.zip |
Patch #1839861 (Possible workaround for bugs related to cloneToFadeOutTrack): Fixes bug #1848399 and apparently also #1527274 & #1763227
svn-id: r30111
Diffstat (limited to 'engines/scumm/imuse_digi/dimuse_track.cpp')
-rw-r--r-- | engines/scumm/imuse_digi/dimuse_track.cpp | 45 |
1 files changed, 24 insertions, 21 deletions
diff --git a/engines/scumm/imuse_digi/dimuse_track.cpp b/engines/scumm/imuse_digi/dimuse_track.cpp index 1a9d59a214..faaae470e7 100644 --- a/engines/scumm/imuse_digi/dimuse_track.cpp +++ b/engines/scumm/imuse_digi/dimuse_track.cpp @@ -59,7 +59,22 @@ int IMuseDigital::allocSlot(int priority) { } if (lowest_priority <= priority) { assert(trackId != -1); - _track[trackId]->toBeRemoved = true; + Track *track = _track[trackId]; + while (1) { + if (!track->used) { + break; + } + // The designated track is not yet available. So, we call flushTrack() + // to get it processed (and thus made ready for us). Since the actual + // processing is done by another thread, we also call parseEvents to + // give it some time (and to avoid busy waiting/looping). + flushTrack(track); + _mutex.unlock(); + #ifndef __PLAYSTATION2__ + _vm->parseEvents(); + #endif + _mutex.lock(); + } debug(5, "IMuseDigital::allocSlot(): Removed sound %d from track %d", _track[trackId]->soundId, trackId); } else { debug(5, "IMuseDigital::allocSlot(): Priority sound too low"); @@ -71,6 +86,7 @@ int IMuseDigital::allocSlot(int priority) { } void IMuseDigital::startSound(int soundId, const char *soundName, int soundType, int volGroupId, Audio::AudioStream *input, int hookId, int volume, int priority) { + Common::StackLock lock(_mutex, "IMuseDigital::startSound()"); debug(5, "IMuseDigital::startSound(%d)", soundId); int l = allocSlot(priority); @@ -80,21 +96,6 @@ void IMuseDigital::startSound(int soundId, const char *soundName, int soundType, } Track *track = _track[l]; - while (1) { - _mutex.lock(); - if (!track->used) { - break; - } - // The designated track is not yet available. So, we call flushTracks() - // to get it processed (and thus made ready for us). Since the actual - // processing is done by another thread, we also call parseEvents to - // give it some time (and to avoid busy waiting/looping). - flushTracks(); - _mutex.unlock(); -#ifndef __PLAYSTATION2__ - _vm->parseEvents(); -#endif - } track->pan = 64; track->vol = volume * 1000; @@ -113,7 +114,6 @@ void IMuseDigital::startSound(int soundId, const char *soundName, int soundType, track->dataMod12Bit = 0; track->mixerFlags = 0; track->toBeRemoved = false; - track->readyToRemove = false; track->soundType = soundType; int bits = 0, freq = 0, channels = 0; @@ -191,7 +191,6 @@ void IMuseDigital::startSound(int soundId, const char *soundName, int soundType, } track->used = true; - _mutex.unlock(); } void IMuseDigital::setPriority(int soundId, int priority) { @@ -309,7 +308,7 @@ void IMuseDigital::fadeOutMusic(int fadeDelay) { Track *track = _track[l]; if (track->used && !track->toBeRemoved && (track->volGroupId == IMUSE_VOLGRP_MUSIC)) { cloneToFadeOutTrack(track, fadeDelay); - track->toBeRemoved = true; + flushTrack(track); } } } @@ -319,9 +318,14 @@ IMuseDigital::Track *IMuseDigital::cloneToFadeOutTrack(Track *track, int fadeDel Track *fadeTrack = 0; debug(0, "IMuseDigital::cloneToFadeOutTrack(%d, %d)", track->trackId, fadeDelay); + + if (track->toBeRemoved) { + error("IMuseDigital::cloneToFadeOutTrack: Tried to clone a track to be removed"); + return NULL; + } if (_track[track->trackId + MAX_DIGITAL_TRACKS]->used) { - warning("IMuseDigital::cloneToFadeOutTrack: Not free fade track"); + warning("IMuseDigital::cloneToFadeOutTrack: No free fade track"); return NULL; } @@ -360,7 +364,6 @@ IMuseDigital::Track *IMuseDigital::cloneToFadeOutTrack(Track *track, int fadeDel } fadeTrack->stream = Audio::makeAppendableAudioStream(_sound->getFreq(fadeTrack->soundDesc), makeMixerFlags(fadeTrack->mixerFlags)); _mixer->playInputStream(type, &fadeTrack->mixChanHandle, fadeTrack->stream, -1, fadeTrack->vol / 1000, fadeTrack->pan, false); - fadeTrack->mixerStreamRunning = true; fadeTrack->used = true; |