From e976b1199538aa32067aed50f1886f2393ca148b Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Fri, 8 Jan 2010 16:25:51 +0000 Subject: Add another makeLoopingAudioStream factory for transparently looping a certain interval of a SeekableAudioStream. svn-id: r47159 --- sound/audiostream.cpp | 16 ++++++++++++++++ sound/audiostream.h | 19 +++++++++++++++++++ 2 files changed, 35 insertions(+) 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 @@ -196,6 +196,25 @@ public: virtual bool rewind() { return seek(0); } }; +/** + * 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). -- cgit v1.2.3