aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Horn2011-06-11 17:37:51 +0200
committerMax Horn2011-06-14 18:17:01 +0200
commite4a4aa30f743395342a4ce9cbd6bf6f3f81d6172 (patch)
treed2c3a537874cccdcee52db97fd2e8aa2c7870884
parent929e7ba4a50876cd065d4d09347f44f0a62b27e1 (diff)
downloadscummvm-rg350-e4a4aa30f743395342a4ce9cbd6bf6f3f81d6172.tar.gz
scummvm-rg350-e4a4aa30f743395342a4ce9cbd6bf6f3f81d6172.tar.bz2
scummvm-rg350-e4a4aa30f743395342a4ce9cbd6bf6f3f81d6172.zip
SWORD1: Cleanup music stream initialization
-rw-r--r--engines/sword1/music.cpp47
1 files changed, 24 insertions, 23 deletions
diff --git a/engines/sword1/music.cpp b/engines/sword1/music.cpp
index 265bebb000..b4656ff89f 100644
--- a/engines/sword1/music.cpp
+++ b/engines/sword1/music.cpp
@@ -54,54 +54,58 @@ bool MusicHandle::play(const Common::String &filename, bool loop) {
// I.e.:
//_audioSource = Audio::AudioStream::openStreamFile(fileBase, 0, 0, loop ? 0 : 1);
+ Audio::RewindableAudioStream *stream = 0;
+
#ifdef USE_FLAC
- if (!_audioSource) {
+ if (!stream) {
if (_file.open(filename + ".flac")) {
- _audioSource = Audio::makeLoopingAudioStream(Audio::makeFLACStream(&_file, DisposeAfterUse::NO), loop ? 0 : 1);
- if (!_audioSource)
+ stream = Audio::makeFLACStream(&_file, DisposeAfterUse::NO);
+ if (!stream)
_file.close();
}
}
- if (!_audioSource) {
+ if (!stream) {
if (_file.open(filename + ".fla")) {
- _audioSource = Audio::makeLoopingAudioStream(Audio::makeFLACStream(&_file, DisposeAfterUse::NO), loop ? 0 : 1);
- if (!_audioSource)
+ stream = Audio::makeFLACStream(&_file, DisposeAfterUse::NO);
+ if (!stream)
_file.close();
}
}
#endif
#ifdef USE_VORBIS
- if (!_audioSource) {
+ if (!stream) {
if (_file.open(filename + ".ogg")) {
- _audioSource = Audio::makeLoopingAudioStream(Audio::makeVorbisStream(&_file, DisposeAfterUse::NO), loop ? 0 : 1);
- if (!_audioSource)
+ stream = Audio::makeVorbisStream(&_file, DisposeAfterUse::NO);
+ if (!stream)
_file.close();
}
}
#endif
#ifdef USE_MAD
- if (!_audioSource) {
+ if (!stream) {
if (_file.open(filename + ".mp3")) {
- _audioSource = Audio::makeLoopingAudioStream(Audio::makeMP3Stream(&_file, DisposeAfterUse::NO), loop ? 0 : 1);
- if (!_audioSource)
+ stream = Audio::makeMP3Stream(&_file, DisposeAfterUse::NO);
+ if (!stream)
_file.close();
}
}
#endif
- if (!_audioSource) {
+ if (!stream) {
if (_file.open(filename + ".wav"))
- _audioSource = Audio::makeLoopingAudioStream(Audio::makeWAVStream(&_file, DisposeAfterUse::NO), loop ? 0 : 1);
+ stream = Audio::makeWAVStream(&_file, DisposeAfterUse::NO);
}
- if (!_audioSource) {
+ if (!stream) {
if (_file.open(filename + ".aif"))
- _audioSource = Audio::makeLoopingAudioStream(Audio::makeAIFFStream(&_file, DisposeAfterUse::NO), loop ? 0 : 1);
+ stream = Audio::makeAIFFStream(&_file, DisposeAfterUse::NO);
}
- if (!_audioSource)
+ if (!stream)
return false;
+ _audioSource = Audio::makeLoopingAudioStream(stream, loop ? 0 : 1);
+
fadeUp();
return true;
}
@@ -212,12 +216,9 @@ int MusicHandle::readBuffer(int16 *buffer, const int numSamples) {
}
void MusicHandle::stop() {
- if (_audioSource) {
- delete _audioSource;
- _audioSource = NULL;
- }
- if (_file.isOpen())
- _file.close();
+ delete _audioSource;
+ _audioSource = NULL;
+ _file.close();
_fading = 0;
}