diff --git a/engines/scumm/imuse_digi/dimuse.cpp b/engines/scumm/imuse_digi/dimuse.cpp index c79cc833eea..0e1752007b0 100644 --- a/engines/scumm/imuse_digi/dimuse.cpp +++ b/engines/scumm/imuse_digi/dimuse.cpp @@ -206,7 +206,7 @@ void IMuseDigital::saveOrLoad(Serializer *ser) { track->stream = Audio::makeAppendableAudioStream(freq, makeMixerFlags(track->mixerFlags)); - _mixer->playInputStream(track->getType(), &track->mixChanHandle, track->stream, -1, track->getVol(), track->getPan(), false); + _mixer->playInputStream(track->getType(), &track->mixChanHandle, track->stream, -1, track->getVol(), track->getPan()); _mixer->pauseHandle(track->mixChanHandle, true); } } diff --git a/engines/scumm/imuse_digi/dimuse_script.cpp b/engines/scumm/imuse_digi/dimuse_script.cpp index 9e3337076ae..185ef80e022 100644 --- a/engines/scumm/imuse_digi/dimuse_script.cpp +++ b/engines/scumm/imuse_digi/dimuse_script.cpp @@ -165,22 +165,26 @@ void IMuseDigital::parseScriptCmds(int cmd, int b, int c, int d, int e, int f, i void IMuseDigital::flushTrack(Track *track) { track->toBeRemoved = true; - if (!track->souStreamUsed) { - assert(track->stream); - // Finalize the appendable stream - track->stream->finish(); - // There might still be some data left in the buffers of the - // appendable stream. We play it nice and wait till all of it - // played. - if (track->stream->endOfStream()) { - _mixer->stopHandle(track->mixChanHandle); - delete track->stream; - _sound->closeSound(track->soundDesc); - memset(track, 0, sizeof(Track)); - } - } else { + + if (track->souStreamUsed) { _mixer->stopHandle(track->mixChanHandle); + } else if (track->stream) { + // Finalize the appendable stream, then remove our reference to it. + // Note that there might still be some data left in the buffers of the + // appendable stream. We play it nice and wait till all of it + // played. The audio mixer will take care of it afterwards (and dispose it). + track->stream->finish(); + track->stream = 0; + if (track->soundDesc) + _sound->closeSound(track->soundDesc); + } + + if (!_mixer->isSoundHandleActive(track->mixChanHandle)) { memset(track, 0, sizeof(Track)); + + // Still set toBeRemoved to true in case we are running inside the callback() + // function + track->toBeRemoved = true; } } @@ -396,9 +400,7 @@ void IMuseDigital::stopAllSounds() { // as we are protected by a mutex, and this method is never called // from IMuseDigital::callback either. _mixer->stopHandle(track->mixChanHandle); - if (!track->souStreamUsed) { - assert(track->stream); - delete track->stream; + if (track->soundDesc) { _sound->closeSound(track->soundDesc); } diff --git a/engines/scumm/imuse_digi/dimuse_track.cpp b/engines/scumm/imuse_digi/dimuse_track.cpp index bc71e71b10e..3da2a5b56c3 100644 --- a/engines/scumm/imuse_digi/dimuse_track.cpp +++ b/engines/scumm/imuse_digi/dimuse_track.cpp @@ -63,9 +63,7 @@ int IMuseDigital::allocSlot(int priority) { // Stop the track immediately _mixer->stopHandle(track->mixChanHandle); - if (!track->souStreamUsed) { - assert(track->stream); - delete track->stream; + if (!track->soundDesc) { _sound->closeSound(track->soundDesc); } @@ -156,7 +154,7 @@ void IMuseDigital::startSound(int soundId, const char *soundName, int soundType, #endif track->stream = Audio::makeAppendableAudioStream(freq, makeMixerFlags(track->mixerFlags)); - _mixer->playInputStream(track->getType(), &track->mixChanHandle, track->stream, -1, track->getVol(), track->getPan(), false); + _mixer->playInputStream(track->getType(), &track->mixChanHandle, track->stream, -1, track->getVol(), track->getPan()); } track->used = true; @@ -317,7 +315,7 @@ IMuseDigital::Track *IMuseDigital::cloneToFadeOutTrack(Track *track, int fadeDel // Create an appendable output buffer fadeTrack->stream = Audio::makeAppendableAudioStream(_sound->getFreq(fadeTrack->soundDesc), makeMixerFlags(fadeTrack->mixerFlags)); - _mixer->playInputStream(track->getType(), &fadeTrack->mixChanHandle, fadeTrack->stream, -1, fadeTrack->getVol(), fadeTrack->getPan(), false); + _mixer->playInputStream(track->getType(), &fadeTrack->mixChanHandle, fadeTrack->stream, -1, fadeTrack->getVol(), fadeTrack->getPan()); fadeTrack->used = true; return fadeTrack;