diff --git a/scumm/imuse_digi/dimuse.cpp b/scumm/imuse_digi/dimuse.cpp index 6633ef5182d..26476f266bd 100644 --- a/scumm/imuse_digi/dimuse.cpp +++ b/scumm/imuse_digi/dimuse.cpp @@ -378,10 +378,12 @@ void IMuseDigital::switchToNextRegion(Track *track) { if (track->curHookId == sampleHookId) { if (fadeDelay != 0) { Track *fadeTrack = cloneToFadeOutTrack(track, fadeDelay); - fadeTrack->dataOffset = _sound->getRegionOffset(fadeTrack->soundHandle, fadeTrack->curRegion); - fadeTrack->regionOffset = 0; - debug(5, "switchToNextRegion-sound(%d) select region %d, curHookId: %d", fadeTrack->soundId, fadeTrack->curRegion, fadeTrack->curHookId); - fadeTrack->curHookId = 0; + if (fadeTrack) { + fadeTrack->dataOffset = _sound->getRegionOffset(fadeTrack->soundHandle, fadeTrack->curRegion); + fadeTrack->regionOffset = 0; + debug(5, "switchToNextRegion-sound(%d) select region %d, curHookId: %d", fadeTrack->soundId, fadeTrack->curRegion, fadeTrack->curHookId); + fadeTrack->curHookId = 0; + } } track->curRegion = region; debug(5, "switchToNextRegion-sound(%d) jump to region %d, curHookId: %d", track->soundId, track->curRegion, track->curHookId); @@ -390,9 +392,11 @@ void IMuseDigital::switchToNextRegion(Track *track) { } else { if (fadeDelay != 0) { Track *fadeTrack = cloneToFadeOutTrack(track, fadeDelay); - fadeTrack->dataOffset = _sound->getRegionOffset(fadeTrack->soundHandle, fadeTrack->curRegion); - fadeTrack->regionOffset = 0; - debug(5, "switchToNextRegion-sound(%d) select region %d, curHookId: %d", fadeTrack->soundId, fadeTrack->curRegion, fadeTrack->curHookId); + if (fadeTrack) { + fadeTrack->dataOffset = _sound->getRegionOffset(fadeTrack->soundHandle, fadeTrack->curRegion); + fadeTrack->regionOffset = 0; + debug(5, "switchToNextRegion-sound(%d) select region %d, curHookId: %d", fadeTrack->soundId, fadeTrack->curRegion, fadeTrack->curHookId); + } } track->curRegion = region; debug(5, "switchToNextRegion-sound(%d) jump to region %d, curHookId: %d", track->soundId, track->curRegion, track->curHookId); diff --git a/scumm/imuse_digi/dimuse_script.cpp b/scumm/imuse_digi/dimuse_script.cpp index fcadf609dc6..0238aa05609 100644 --- a/scumm/imuse_digi/dimuse_script.cpp +++ b/scumm/imuse_digi/dimuse_script.cpp @@ -160,6 +160,7 @@ void IMuseDigital::parseScriptCmds(int cmd, int b, int c, int d, int e, int f, i } void IMuseDigital::flushTracks() { + Common::StackLock lock(_mutex, "IMuseDigital::flushTracks()"); debug(5, "flushTracks()"); for (int l = 0; l < MAX_DIGITAL_TRACKS + MAX_DIGITAL_FADETRACKS; l++) { Track *track = _track[l]; @@ -190,6 +191,7 @@ void IMuseDigital::flushTracks() { } void IMuseDigital::refreshScripts() { + Common::StackLock lock(_mutex, "IMuseDigital::refreshScripts()"); debug(5, "refreshScripts()"); bool found = false; for (int l = 0; l < MAX_DIGITAL_TRACKS; l++) { @@ -236,6 +238,7 @@ void IMuseDigital::getLipSync(int soundId, int syncId, int32 msPos, int32 &width msPos /= 16; if (msPos < 65536) { + Common::StackLock lock(_mutex, "IMuseDigital::getLipSync()"); for (int l = 0; l < MAX_DIGITAL_TRACKS; l++) { Track *track = _track[l]; if ((track->soundId == soundId) && track->used && !track->toBeRemoved) { @@ -263,6 +266,7 @@ void IMuseDigital::getLipSync(int soundId, int syncId, int32 msPos, int32 &width } int32 IMuseDigital::getPosInMs(int soundId) { + Common::StackLock lock(_mutex, "IMuseDigital::getPosInMs()"); for (int l = 0; l < MAX_DIGITAL_TRACKS; l++) { Track *track = _track[l]; if ((track->soundId == soundId) && track->used && !track->toBeRemoved) { @@ -275,6 +279,7 @@ int32 IMuseDigital::getPosInMs(int soundId) { } int IMuseDigital::getSoundStatus(int sound) const { + Common::StackLock lock(_mutex, "IMuseDigital::getSoundStatus()"); debug(5, "IMuseDigital::getSoundStatus(%d)", sound); for (int l = 0; l < MAX_DIGITAL_TRACKS; l++) { Track *track = _track[l]; @@ -290,6 +295,7 @@ int IMuseDigital::getSoundStatus(int sound) const { } void IMuseDigital::stopSound(int soundId) { + Common::StackLock lock(_mutex, "IMuseDigital::stopSound()"); debug(5, "IMuseDigital::stopSound(%d)", soundId); for (int l = 0; l < MAX_DIGITAL_TRACKS; l++) { Track *track = _track[l]; @@ -300,6 +306,7 @@ void IMuseDigital::stopSound(int soundId) { } int32 IMuseDigital::getCurMusicPosInMs() { + Common::StackLock lock(_mutex, "IMuseDigital::getCurMusicPosInMs()"); int soundId = -1; for (int l = 0; l < MAX_DIGITAL_TRACKS; l++) { @@ -315,6 +322,7 @@ int32 IMuseDigital::getCurMusicPosInMs() { } int32 IMuseDigital::getCurVoiceLipSyncWidth() { + Common::StackLock lock(_mutex, "IMuseDigital::getCurVoiceLipSyncWidth()"); int32 msPos = getPosInMs(kTalkSoundID) + 50; int32 width = 0, height = 0; @@ -324,6 +332,7 @@ int32 IMuseDigital::getCurVoiceLipSyncWidth() { } int32 IMuseDigital::getCurVoiceLipSyncHeight() { + Common::StackLock lock(_mutex, "IMuseDigital::getCurVoiceLipSyncHeight()"); int32 msPos = getPosInMs(kTalkSoundID) + 50; int32 width = 0, height = 0; @@ -333,6 +342,7 @@ int32 IMuseDigital::getCurVoiceLipSyncHeight() { } int32 IMuseDigital::getCurMusicLipSyncWidth(int syncId) { + Common::StackLock lock(_mutex, "IMuseDigital::getCurMusicLipSyncWidth()"); int soundId = -1; for (int l = 0; l < MAX_DIGITAL_TRACKS; l++) { @@ -351,6 +361,7 @@ int32 IMuseDigital::getCurMusicLipSyncWidth(int syncId) { } int32 IMuseDigital::getCurMusicLipSyncHeight(int syncId) { + Common::StackLock lock(_mutex, "IMuseDigital::getCurMusicLipSyncHeight()"); int soundId = -1; for (int l = 0; l < MAX_DIGITAL_TRACKS; l++) { diff --git a/scumm/imuse_digi/dimuse_track.cpp b/scumm/imuse_digi/dimuse_track.cpp index 3723705c142..8d97f9017d9 100644 --- a/scumm/imuse_digi/dimuse_track.cpp +++ b/scumm/imuse_digi/dimuse_track.cpp @@ -186,6 +186,7 @@ void IMuseDigital::startSound(int soundId, const char *soundName, int soundType, } void IMuseDigital::setPriority(int soundId, int priority) { + Common::StackLock lock(_mutex, "IMuseDigital::setPriority()"); debug(5, "IMuseDigital::setPriority(%d, %d)", soundId, priority); assert ((priority >= 0) && (priority <= 127)); @@ -198,6 +199,7 @@ void IMuseDigital::setPriority(int soundId, int priority) { } void IMuseDigital::setVolume(int soundId, int volume) { + Common::StackLock lock(_mutex, "IMuseDigital::setVolume()"); debug(5, "IMuseDigital::setVolume(%d, %d)", soundId, volume); for (int l = 0; l < MAX_DIGITAL_TRACKS; l++) { @@ -220,6 +222,7 @@ void IMuseDigital::setHookId(int soundId, int hookId) { } int IMuseDigital::getCurMusicSoundId() { + Common::StackLock lock(_mutex, "IMuseDigital::getCurMusicSoundId()"); int soundId = -1; for (int l = 0; l < MAX_DIGITAL_TRACKS; l++) { @@ -233,6 +236,7 @@ int IMuseDigital::getCurMusicSoundId() { } char *IMuseDigital::getCurMusicSoundName() { + Common::StackLock lock(_mutex, "IMuseDigital::getCurMusicSoundName()"); char *soundName = NULL; for (int l = 0; l < MAX_DIGITAL_TRACKS; l++) { @@ -246,6 +250,7 @@ char *IMuseDigital::getCurMusicSoundName() { } void IMuseDigital::setPan(int soundId, int pan) { + Common::StackLock lock(_mutex, "IMuseDigital::setPan()"); debug(5, "IMuseDigital::setPan(%d, %d)", soundId, pan); for (int l = 0; l < MAX_DIGITAL_TRACKS; l++) { @@ -257,6 +262,7 @@ void IMuseDigital::setPan(int soundId, int pan) { } void IMuseDigital::selectVolumeGroup(int soundId, int volGroupId) { + Common::StackLock lock(_mutex, "IMuseDigital::selectVolumeGroup()"); debug(5, "IMuseDigital::setGroupVolume(%d, %d)", soundId, volGroupId); assert((volGroupId >= 1) && (volGroupId <= 4)); @@ -287,7 +293,9 @@ void IMuseDigital::setFade(int soundId, int destVolume, int delay60HzTicks) { } void IMuseDigital::fadeOutMusic(int fadeDelay) { + Common::StackLock lock(_mutex, "IMuseDigital::fadeOutMusic()"); debug(5, "IMuseDigital::fadeOutMusic"); + for (int l = 0; l < MAX_DIGITAL_TRACKS; l++) { Track *track = _track[l]; if (track->used && !track->toBeRemoved && (track->volGroupId == IMUSE_VOLGRP_MUSIC)) { @@ -298,45 +306,40 @@ void IMuseDigital::fadeOutMusic(int fadeDelay) { } IMuseDigital::Track *IMuseDigital::cloneToFadeOutTrack(Track *track, int fadeDelay) { + Common::StackLock lock(_mutex, "IMuseDigital::cloneToFadeOutTrack()"); assert(track); Track *fadeTrack = 0; debug(5, "IMuseDigital::cloneToFadeOutTrack(%d, %d)", track->trackId, fadeDelay); - { - Common::StackLock lock(_mutex, "IMuseDigital::cloneToFadeOutTrack()"); - for (int l = MAX_DIGITAL_TRACKS; l < MAX_DIGITAL_TRACKS + MAX_DIGITAL_FADETRACKS; l++) { - if (!_track[l]->used) { - fadeTrack = _track[l]; - break; - } - } - if (fadeTrack == 0) - error("IMuseDigital::cloneToFadeOutTrack() Can't find free fade track"); - - fadeTrack->pan = track->pan; - fadeTrack->vol = track->vol; - fadeTrack->volGroupId = track->volGroupId; - fadeTrack->priority = track->priority; - fadeTrack->soundId = track->soundId; - fadeTrack->dataOffset = track->dataOffset; - fadeTrack->regionOffset = track->regionOffset; - fadeTrack->curRegion = track->curRegion; - fadeTrack->curHookId = track->curHookId; - fadeTrack->iteration = track->iteration; - fadeTrack->mixerFlags = track->mixerFlags; - fadeTrack->mod = track->mod; - fadeTrack->toBeRemoved = track->toBeRemoved; - fadeTrack->readyToRemove = track->readyToRemove; - fadeTrack->souStream = track->souStream; - fadeTrack->started = track->started; - fadeTrack->stream2 = track->stream2; - strcpy(fadeTrack->soundName, track->soundName); - fadeTrack->soundType = track->soundType; - fadeTrack->soundHandle = _sound->cloneSound(track->soundHandle); - assert(fadeTrack->soundHandle); + if (_track[track->trackId + MAX_DIGITAL_TRACKS]->used) { + warning("IMuseDigital::cloneToFadeOutTrack: Not free fade track"); + return NULL; } + fadeTrack = _track[track->trackId + MAX_DIGITAL_TRACKS]; + fadeTrack->pan = track->pan; + fadeTrack->vol = track->vol; + fadeTrack->volGroupId = track->volGroupId; + fadeTrack->priority = track->priority; + fadeTrack->soundId = track->soundId; + fadeTrack->dataOffset = track->dataOffset; + fadeTrack->regionOffset = track->regionOffset; + fadeTrack->curRegion = track->curRegion; + fadeTrack->curHookId = track->curHookId; + fadeTrack->iteration = track->iteration; + fadeTrack->mixerFlags = track->mixerFlags; + fadeTrack->mod = track->mod; + fadeTrack->toBeRemoved = track->toBeRemoved; + fadeTrack->readyToRemove = track->readyToRemove; + fadeTrack->souStream = track->souStream; + fadeTrack->started = track->started; + fadeTrack->stream2 = track->stream2; + strcpy(fadeTrack->soundName, track->soundName); + fadeTrack->soundType = track->soundType; + fadeTrack->soundHandle = _sound->cloneSound(track->soundHandle); + assert(fadeTrack->soundHandle); + fadeTrack->volFadeDelay = fadeDelay; fadeTrack->volFadeDest = 0; fadeTrack->volFadeStep = (fadeTrack->volFadeDest - fadeTrack->vol) * 60 * (1000 / _callbackFps) / (1000 * fadeDelay);