Let the audio mixer take care of (i.e. dispose) the Track::stream object, too

svn-id: r30277
This commit is contained in:
Max Horn 2008-01-05 23:53:28 +00:00
parent ef9dac103f
commit 1d34ce3baa
3 changed files with 23 additions and 23 deletions

View File

@ -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);
}
}

View File

@ -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);
}

View File

@ -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;