aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engines/mohawk/sound.cpp7
-rw-r--r--sound/audiostream.cpp7
-rw-r--r--sound/audiostream.h16
-rw-r--r--sound/flac.cpp5
-rw-r--r--sound/mp3.cpp5
-rw-r--r--sound/vorbis.cpp5
-rw-r--r--sound/wave.cpp19
7 files changed, 31 insertions, 33 deletions
diff --git a/engines/mohawk/sound.cpp b/engines/mohawk/sound.cpp
index 54f8a75842..59dc6c1151 100644
--- a/engines/mohawk/sound.cpp
+++ b/engines/mohawk/sound.cpp
@@ -444,12 +444,7 @@ Audio::AudioStream *Sound::makeMohawkWaveStream(Common::SeekableReadStream *stre
Common::MemoryReadStream *dataStream = new Common::MemoryReadStream(data_chunk.audio_data, data_chunk.size, Common::DisposeAfterUse::YES);
uint32 blockAlign = data_chunk.channels * data_chunk.bitsPerSample / 8;
- Audio::RewindableAudioStream *audio = Audio::makeADPCMStream(dataStream, true, data_chunk.size, Audio::kADPCMIma, data_chunk.sample_rate, data_chunk.channels, blockAlign);
-
- if (loop)
- return new Audio::LoopingAudioStream(audio, 0);
- else
- return audio;
+ return makeLoopingAudioStream(Audio::makeADPCMStream(dataStream, true, data_chunk.size, Audio::kADPCMIma, data_chunk.sample_rate, data_chunk.channels, blockAlign), loop ? 0 : 1);
} else if (data_chunk.encoding == kCodecMPEG2) {
#ifdef USE_MAD
Common::MemoryReadStream *dataStream = new Common::MemoryReadStream(data_chunk.audio_data, data_chunk.size, Common::DisposeAfterUse::YES);
diff --git a/sound/audiostream.cpp b/sound/audiostream.cpp
index 04f41ccf5c..5e6b25740f 100644
--- a/sound/audiostream.cpp
+++ b/sound/audiostream.cpp
@@ -137,6 +137,13 @@ bool LoopingAudioStream::endOfData() const {
return (_loops != 0 && (_completeIterations == _loops));
}
+AudioStream *makeLoopingAudioStream(RewindableAudioStream *stream, uint loops) {
+ if (loops != 1)
+ return new LoopingAudioStream(stream, loops);
+ else
+ return stream;
+}
+
#pragma mark -
#pragma mark --- SubSeekableAudioStream ---
#pragma mark -
diff --git a/sound/audiostream.h b/sound/audiostream.h
index 15dce74661..fbb84bcf53 100644
--- a/sound/audiostream.h
+++ b/sound/audiostream.h
@@ -125,6 +125,8 @@ public:
/**
* Creates a looping audio stream object.
*
+ * @see makeLoopingAudioStream
+ *
* @param stream Stream to loop
* @param loops How often to loop (0 = infinite)
* @param disposeAfteruse Destroy the stream after the LoopingAudioStream has finished playback.
@@ -152,6 +154,20 @@ private:
};
/**
+ * Wrapper functionallity to efficiently create a stream, which might be looped.
+ *
+ * Note that this function does not return a LoopingAudioStream, because it does
+ * not create one, when the loop count is "1". This allows to keep the runtime
+ * overhead down, when the code does not require any functionallity only offered
+ * by LoopingAudioStream.
+ *
+ * @param stream Stream to loop (will be automatically destroyed, when the looping is done)
+ * @param loops How often to loop (0 = infinite)
+ * @return A new AudioStream, which offers the desired functionallity.
+ */
+AudioStream *makeLoopingAudioStream(RewindableAudioStream *stream, uint loops);
+
+/**
* A seekable audio stream. Subclasses of this class implement an
* interface for seeking. The seeking itself is not required to be
* working while the stream is being played by Mixer!
diff --git a/sound/flac.cpp b/sound/flac.cpp
index 2036156991..d225822889 100644
--- a/sound/flac.cpp
+++ b/sound/flac.cpp
@@ -745,10 +745,7 @@ AudioStream *makeFlacStream(
assert(input);
}
- if (numLoops)
- return new LoopingAudioStream(input, numLoops);
- else
- return input;
+ return makeLoopingAudioStream(input, numLoops);
}
SeekableAudioStream *makeFlacStream(
diff --git a/sound/mp3.cpp b/sound/mp3.cpp
index 2ee4637a83..f5b6420c4f 100644
--- a/sound/mp3.cpp
+++ b/sound/mp3.cpp
@@ -358,10 +358,7 @@ AudioStream *makeMP3Stream(
assert(mp3);
}
- if (numLoops)
- return new LoopingAudioStream(mp3, numLoops);
- else
- return mp3;
+ return makeLoopingAudioStream(mp3, numLoops);
}
SeekableAudioStream *makeMP3Stream(
diff --git a/sound/vorbis.cpp b/sound/vorbis.cpp
index 55c676cfed..54d9042cf8 100644
--- a/sound/vorbis.cpp
+++ b/sound/vorbis.cpp
@@ -260,10 +260,7 @@ AudioStream *makeVorbisStream(
assert(input);
}
- if (numLoops)
- return new LoopingAudioStream(input, numLoops);
- else
- return input;
+ return makeLoopingAudioStream(input, numLoops);
}
SeekableAudioStream *makeVorbisStream(
diff --git a/sound/wave.cpp b/sound/wave.cpp
index 67aa7daa54..bcae1b7f10 100644
--- a/sound/wave.cpp
+++ b/sound/wave.cpp
@@ -173,21 +173,10 @@ AudioStream *makeWAVStream(Common::SeekableReadStream *stream, bool disposeAfter
return 0;
}
- if (type == 17) { // MS IMA ADPCM
- RewindableAudioStream *adpcm = makeADPCMStream(stream, disposeAfterUse, size, Audio::kADPCMMSIma, rate, (flags & Audio::Mixer::FLAG_STEREO) ? 2 : 1, blockAlign);
-
- if (loop)
- return new LoopingAudioStream(adpcm, 0);
- else
- return adpcm;
- } else if (type == 2) { // MS ADPCM
- RewindableAudioStream *adpcm = makeADPCMStream(stream, disposeAfterUse, size, Audio::kADPCMMS, rate, (flags & Audio::Mixer::FLAG_STEREO) ? 2 : 1, blockAlign);
-
- if (loop)
- return new LoopingAudioStream(adpcm, 0);
- else
- return adpcm;
- }
+ if (type == 17) // MS IMA ADPCM
+ return makeLoopingAudioStream(makeADPCMStream(stream, disposeAfterUse, size, Audio::kADPCMMSIma, rate, (flags & Audio::Mixer::FLAG_STEREO) ? 2 : 1, blockAlign), loop ? 0 : 1);
+ else if (type == 2) // MS ADPCM
+ return makeLoopingAudioStream(makeADPCMStream(stream, disposeAfterUse, size, Audio::kADPCMMS, rate, (flags & Audio::Mixer::FLAG_STEREO) ? 2 : 1, blockAlign), loop ? 0 : 1);
// Raw PCM. Just read everything at once.
// TODO: More elegant would be to wrap the stream.