aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Horn2010-03-08 10:27:42 +0000
committerMax Horn2010-03-08 10:27:42 +0000
commitf24cc1c8be08448c8412afef29be3ffa4ff09dd5 (patch)
tree28c0d14608cae4af3685afb41da2e7651b77a20e
parent50116130efedc66ec8261df6080fb7ca6fe079f7 (diff)
downloadscummvm-rg350-f24cc1c8be08448c8412afef29be3ffa4ff09dd5.tar.gz
scummvm-rg350-f24cc1c8be08448c8412afef29be3ffa4ff09dd5.tar.bz2
scummvm-rg350-f24cc1c8be08448c8412afef29be3ffa4ff09dd5.zip
Tweak makeVOCDiskStream
* now takes a SeekableReadStream *pointer* like (almost) all other audiostream factories * fix potential memory leak in it * rename takeOwnershipOfStream to disposeAfterUse for consistency svn-id: r48184
-rw-r--r--engines/agos/sound.cpp2
-rw-r--r--engines/kyra/sound.cpp4
-rw-r--r--engines/scumm/sound.cpp2
-rw-r--r--engines/touche/resource.cpp4
-rw-r--r--sound/decoders/voc.cpp34
-rw-r--r--sound/decoders/voc.h4
6 files changed, 28 insertions, 22 deletions
diff --git a/engines/agos/sound.cpp b/engines/agos/sound.cpp
index 06ba6246e5..84b0eebe69 100644
--- a/engines/agos/sound.cpp
+++ b/engines/agos/sound.cpp
@@ -260,7 +260,7 @@ public:
Audio::AudioStream *VocSound::makeAudioStream(uint sound) {
assert(_offsets);
_file->seek(_offsets[sound], SEEK_SET);
- return Audio::makeVOCStream(*_file, _flags);
+ return Audio::makeVOCStream(_file, _flags);
}
void VocSound::playSound(uint sound, uint loopSound, Audio::Mixer::SoundType type, Audio::SoundHandle *handle, bool loop, int vol) {
diff --git a/engines/kyra/sound.cpp b/engines/kyra/sound.cpp
index 9b049eb2d6..f25a4833a2 100644
--- a/engines/kyra/sound.cpp
+++ b/engines/kyra/sound.cpp
@@ -245,9 +245,9 @@ namespace {
Audio::SeekableAudioStream *makeVOCStream(Common::SeekableReadStream *stream, DisposeAfterUse::Flag disposeAfterUse) {
#ifdef STREAM_AUDIO_FROM_DISK
- Audio::SeekableAudioStream *as = Audio::makeVOCStream(*stream, Audio::FLAG_UNSIGNED, disposeAfterUse);
+ Audio::SeekableAudioStream *as = Audio::makeVOCStream(stream, Audio::FLAG_UNSIGNED, disposeAfterUse);
#else
- Audio::SeekableAudioStream *as = Audio::makeVOCStream(*stream, Audio::FLAG_UNSIGNED, DisposeAfterUse::NO);
+ Audio::SeekableAudioStream *as = Audio::makeVOCStream(stream, Audio::FLAG_UNSIGNED, DisposeAfterUse::NO);
if (disposeAfterUse)
delete stream;
diff --git a/engines/scumm/sound.cpp b/engines/scumm/sound.cpp
index 19be224356..22e56ede3b 100644
--- a/engines/scumm/sound.cpp
+++ b/engines/scumm/sound.cpp
@@ -662,7 +662,7 @@ void Sound::startTalkSound(uint32 offset, uint32 b, int mode, Audio::SoundHandle
#endif
break;
default:
- input = Audio::makeVOCStream(*_sfxFile, Audio::FLAG_UNSIGNED);
+ input = Audio::makeVOCStream(_sfxFile, Audio::FLAG_UNSIGNED);
break;
}
diff --git a/engines/touche/resource.cpp b/engines/touche/resource.cpp
index dead9ae4c7..6e0b0220b7 100644
--- a/engines/touche/resource.cpp
+++ b/engines/touche/resource.cpp
@@ -588,7 +588,7 @@ void ToucheEngine::res_loadSound(int priority, int num) {
uint32 size;
const uint32 offs = res_getDataOffset(kResourceTypeSound, num, &size);
_fData.seek(offs);
- Audio::AudioStream *stream = Audio::makeVOCStream(_fData, Audio::FLAG_UNSIGNED);
+ Audio::AudioStream *stream = Audio::makeVOCStream(&_fData, Audio::FLAG_UNSIGNED);
if (stream) {
_mixer->playInputStream(Audio::Mixer::kSFXSoundType, &_sfxHandle, stream);
}
@@ -646,7 +646,7 @@ void ToucheEngine::res_loadSpeechSegment(int num) {
return;
}
_fSpeech[i].seek(offs);
- stream = Audio::makeVOCStream(_fSpeech[i], Audio::FLAG_UNSIGNED);
+ stream = Audio::makeVOCStream(&_fSpeech[i], Audio::FLAG_UNSIGNED);
} else {
if (num >= 750) {
num -= 750;
diff --git a/sound/decoders/voc.cpp b/sound/decoders/voc.cpp
index 9acc4430d9..5663861f05 100644
--- a/sound/decoders/voc.cpp
+++ b/sound/decoders/voc.cpp
@@ -299,40 +299,40 @@ int parseVOCFormat(Common::SeekableReadStream& stream, RawStreamBlock* block, in
return currentBlock;
}
-AudioStream *makeVOCDiskStream(Common::SeekableReadStream &stream, byte flags, DisposeAfterUse::Flag takeOwnership) {
+AudioStream *makeVOCDiskStream(Common::SeekableReadStream *stream, byte flags, DisposeAfterUse::Flag disposeAfterUse) {
const int MAX_AUDIO_BLOCKS = 256;
RawStreamBlock *block = new RawStreamBlock[MAX_AUDIO_BLOCKS];
int rate, loops, begin_loop, end_loop;
- int numBlocks = parseVOCFormat(stream, block, rate, loops, begin_loop, end_loop);
+ int numBlocks = parseVOCFormat(*stream, block, rate, loops, begin_loop, end_loop);
AudioStream *audioStream = 0;
// Create an audiostream from the data. Note the numBlocks may be 0,
// e.g. when invalid data is encountered. See bug #2890038.
if (numBlocks)
- audioStream = makeRawDiskStream_OLD(&stream, block, numBlocks, rate, flags, takeOwnership/*, begin_loop, end_loop*/);
+ audioStream = makeRawDiskStream_OLD(stream, block, numBlocks, rate, flags, disposeAfterUse/*, begin_loop, end_loop*/);
delete[] block;
return audioStream;
}
-SeekableAudioStream *makeVOCDiskStreamNoLoop(Common::SeekableReadStream &stream, byte flags, DisposeAfterUse::Flag takeOwnership) {
+SeekableAudioStream *makeVOCDiskStreamNoLoop(Common::SeekableReadStream *stream, byte flags, DisposeAfterUse::Flag disposeAfterUse) {
const int MAX_AUDIO_BLOCKS = 256;
RawStreamBlock *block = new RawStreamBlock[MAX_AUDIO_BLOCKS];
int rate, loops, begin_loop, end_loop;
- int numBlocks = parseVOCFormat(stream, block, rate, loops, begin_loop, end_loop);
+ int numBlocks = parseVOCFormat(*stream, block, rate, loops, begin_loop, end_loop);
SeekableAudioStream *audioStream = 0;
// Create an audiostream from the data. Note the numBlocks may be 0,
// e.g. when invalid data is encountered. See bug #2890038.
if (numBlocks)
- audioStream = makeRawDiskStream_OLD(&stream, block, numBlocks, rate, flags, takeOwnership);
+ audioStream = makeRawDiskStream_OLD(stream, block, numBlocks, rate, flags, disposeAfterUse);
delete[] block;
@@ -342,16 +342,19 @@ SeekableAudioStream *makeVOCDiskStreamNoLoop(Common::SeekableReadStream &stream,
#endif
-AudioStream *makeVOCStream(Common::SeekableReadStream &stream, byte flags, uint loopStart, uint loopEnd, DisposeAfterUse::Flag takeOwnershipOfStream) {
+AudioStream *makeVOCStream(Common::SeekableReadStream *stream, byte flags, uint loopStart, uint loopEnd, DisposeAfterUse::Flag disposeAfterUse) {
#ifdef STREAM_AUDIO_FROM_DISK
- return makeVOCDiskStream(stream, flags, takeOwnershipOfStream);
+ return makeVOCDiskStream(stream, flags, disposeAfterUse);
#else
int size, rate;
- byte *data = loadVOCFromStream(stream, size, rate);
+ byte *data = loadVOCFromStream(*stream, size, rate);
- if (!data)
+ if (!data) {
+ if (disposeAfterUse == DisposeAfterUse::YES)
+ delete stream;
return 0;
+ }
SeekableAudioStream *s = Audio::makeRawStream(data, size, rate, flags);
@@ -379,16 +382,19 @@ AudioStream *makeVOCStream(Common::SeekableReadStream &stream, byte flags, uint
#endif
}
-SeekableAudioStream *makeVOCStream(Common::SeekableReadStream &stream, byte flags, DisposeAfterUse::Flag takeOwnershipOfStream) {
+SeekableAudioStream *makeVOCStream(Common::SeekableReadStream *stream, byte flags, DisposeAfterUse::Flag disposeAfterUse) {
#ifdef STREAM_AUDIO_FROM_DISK
- return makeVOCDiskStreamNoLoop(stream, flags, takeOwnershipOfStream);
+ return makeVOCDiskStreamNoLoop(*stream, flags, disposeAfterUse);
#else
int size, rate;
- byte *data = loadVOCFromStream(stream, size, rate);
+ byte *data = loadVOCFromStream(*stream, size, rate);
- if (!data)
+ if (!data) {
+ if (disposeAfterUse == DisposeAfterUse::YES)
+ delete stream;
return 0;
+ }
return makeRawStream(data, size, rate, flags);
#endif
diff --git a/sound/decoders/voc.h b/sound/decoders/voc.h
index 191f42db02..79956ee62a 100644
--- a/sound/decoders/voc.h
+++ b/sound/decoders/voc.h
@@ -95,12 +95,12 @@ extern byte *loadVOCFromStream(Common::ReadStream &stream, int &size, int &rate)
*
* This function uses loadVOCFromStream() internally.
*/
-AudioStream *makeVOCStream(Common::SeekableReadStream &stream, byte flags = 0, uint loopStart = 0, uint loopEnd = 0, DisposeAfterUse::Flag disposeAfterUse = DisposeAfterUse::NO);
+AudioStream *makeVOCStream(Common::SeekableReadStream *stream, byte flags = 0, uint loopStart = 0, uint loopEnd = 0, DisposeAfterUse::Flag disposeAfterUse = DisposeAfterUse::NO);
/**
* This does not use any of the looping features of VOC files!
*/
-SeekableAudioStream *makeVOCStream(Common::SeekableReadStream &stream, byte flags, DisposeAfterUse::Flag disposeAfterUse);
+SeekableAudioStream *makeVOCStream(Common::SeekableReadStream *stream, byte flags, DisposeAfterUse::Flag disposeAfterUse);
} // End of namespace Audio