Skip to content

Commit

Permalink
SCI32: Destroy audio streams in Audio32 using DisposeAfterUse flag
Browse files Browse the repository at this point in the history
Since Resource::makeStream returns a MemoryReadStream which will
not attempt to free the resource memory, it is fine to always
dispose those streams and get rid of the separate resourceStream
property, which was a holdover from some past WIP resource design
which no longer exists.
  • Loading branch information
csnover committed Jul 18, 2017
1 parent 64d090d commit dcb6c32
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
10 changes: 4 additions & 6 deletions engines/sci/sound/audio32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -557,8 +557,6 @@ void Audio32::freeChannel(const int16 channelIndex) {
channel.resource = nullptr;
delete channel.stream;
channel.stream = nullptr;
delete channel.resourceStream;
channel.resourceStream = nullptr;
}

delete channel.converter;
Expand Down Expand Up @@ -797,14 +795,14 @@ uint16 Audio32::play(int16 channelIndex, const ResourceId resourceId, const bool
_monitoredChannelIndex = channelIndex;
}

Common::SeekableReadStream *dataStream = channel.resourceStream = resource->makeStream();
Common::SeekableReadStream *dataStream = resource->makeStream();

Audio::RewindableAudioStream *audioStream;

if (detectSolAudio(*dataStream)) {
audioStream = makeSOLStream(dataStream, DisposeAfterUse::NO);
audioStream = makeSOLStream(dataStream, DisposeAfterUse::YES);
} else if (detectWaveAudio(*dataStream)) {
audioStream = Audio::makeWAVStream(dataStream, DisposeAfterUse::NO);
audioStream = Audio::makeWAVStream(dataStream, DisposeAfterUse::YES);
} else {
byte flags = Audio::FLAG_LITTLE_ENDIAN;
if (_globalBitDepth == 16) {
Expand All @@ -817,7 +815,7 @@ uint16 Audio32::play(int16 channelIndex, const ResourceId resourceId, const bool
flags |= Audio::FLAG_STEREO;
}

audioStream = Audio::makeRawStream(dataStream, _globalSampleRate, flags, DisposeAfterUse::NO);
audioStream = Audio::makeRawStream(dataStream, _globalSampleRate, flags, DisposeAfterUse::YES);
}

channel.stream = new MutableLoopAudioStream(audioStream, loop);
Expand Down
5 changes: 0 additions & 5 deletions engines/sci/sound/audio32.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,6 @@ struct AudioChannel {
*/
Resource *resource;

/**
* Data stream containing the raw audio for the channel.
*/
Common::SeekableReadStream *resourceStream;

/**
* The audio stream loaded into this channel. Can cast
* to `SeekableAudioStream` for normal channels and
Expand Down

0 comments on commit dcb6c32

Please sign in to comment.