aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Schickel2010-01-08 16:25:51 +0000
committerJohannes Schickel2010-01-08 16:25:51 +0000
commite976b1199538aa32067aed50f1886f2393ca148b (patch)
tree143831ac2cdca1726c373fc253ba9c6ac6cb1cbc
parentabdebd9871aa4b07ced645ea76a2274f2dc80f48 (diff)
downloadscummvm-rg350-e976b1199538aa32067aed50f1886f2393ca148b.tar.gz
scummvm-rg350-e976b1199538aa32067aed50f1886f2393ca148b.tar.bz2
scummvm-rg350-e976b1199538aa32067aed50f1886f2393ca148b.zip
Add another makeLoopingAudioStream factory for transparently looping a certain interval of a SeekableAudioStream.
svn-id: r47159
-rw-r--r--sound/audiostream.cpp16
-rw-r--r--sound/audiostream.h19
2 files changed, 35 insertions, 0 deletions
diff --git a/sound/audiostream.cpp b/sound/audiostream.cpp
index f16011ce52..ea71c161e8 100644
--- a/sound/audiostream.cpp
+++ b/sound/audiostream.cpp
@@ -144,6 +144,22 @@ AudioStream *makeLoopingAudioStream(RewindableAudioStream *stream, uint loops) {
return stream;
}
+AudioStream *makeLoopingAudioStream(SeekableAudioStream *stream, Timestamp start, Timestamp end, uint loops) {
+ if (!start.totalNumberOfFrames() && (!end.totalNumberOfFrames() || end == stream->getLength())) {
+ return makeLoopingAudioStream(stream, loops);
+ } else {
+ if (!end.totalNumberOfFrames())
+ end = stream->getLength();
+
+ if (start > end) {
+ delete stream;
+ return 0;
+ }
+
+ return makeLoopingAudioStream(new SubSeekableAudioStream(stream, start, end), loops);
+ }
+}
+
#pragma mark -
#pragma mark --- SubSeekableAudioStream ---
#pragma mark -
diff --git a/sound/audiostream.h b/sound/audiostream.h
index 85807e8134..e418c2d524 100644
--- a/sound/audiostream.h
+++ b/sound/audiostream.h
@@ -197,6 +197,25 @@ public:
};
/**
+ * Wrapper functionallity to efficiently create a stream, which might be looped
+ * in a certain interval.
+ *
+ * This automatically starts the stream at time "start"!
+ *
+ * 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 start Starttime of the stream interval to be looped
+ * @param end End of the stream interval to be looped (a zero time, means till end)
+ * @param loops How often to loop (0 = infinite)
+ * @return A new AudioStream, which offers the desired functionallity.
+ */
+AudioStream *makeLoopingAudioStream(SeekableAudioStream *stream, Timestamp start, Timestamp end, uint loops);
+
+/**
* A SubSeekableAudioStream provides access to a SeekableAudioStream
* just in the range [start, end).
* The same caveats apply to SubSeekableAudioStream as do to SeekableAudioStream.