aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Horn2008-05-24 22:41:15 +0000
committerMax Horn2008-05-24 22:41:15 +0000
commit68fd8b74b0a42279056a4143455bb8b40dc83ca9 (patch)
treea76c9b9787551c6f02f919add9b7fe2574568ee4
parentf2d72d9473be5dd3d942976e8ed84d58d746def9 (diff)
downloadscummvm-rg350-68fd8b74b0a42279056a4143455bb8b40dc83ca9.tar.gz
scummvm-rg350-68fd8b74b0a42279056a4143455bb8b40dc83ca9.tar.bz2
scummvm-rg350-68fd8b74b0a42279056a4143455bb8b40dc83ca9.zip
Patch #1970427: AudioStream play length querying
svn-id: r32258
-rw-r--r--sound/audiostream.cpp15
-rw-r--r--sound/audiostream.h14
2 files changed, 25 insertions, 4 deletions
diff --git a/sound/audiostream.cpp b/sound/audiostream.cpp
index 0fba6affdb..4454a09fe6 100644
--- a/sound/audiostream.cpp
+++ b/sound/audiostream.cpp
@@ -102,6 +102,11 @@ AudioStream* AudioStream::openStreamFile(const Common::String &basename, uint32
#pragma mark --- LinearMemoryStream ---
#pragma mark -
+inline int32 calculatePlayTime(int rate, int samples) {
+ int32 seconds = samples / rate;
+ int32 milliseconds = (1000 * (samples % rate)) / rate;
+ return seconds * 1000 + milliseconds;
+}
/**
* A simple raw audio stream, purely memory based. It operates on a single
@@ -122,10 +127,11 @@ protected:
const byte *_loopEnd;
const int _rate;
const byte *_origPtr;
+ const int32 _playtime;
public:
LinearMemoryStream(int rate, const byte *ptr, uint len, uint loopOffset, uint loopLen, bool autoFreeMemory)
- : _ptr(ptr), _end(ptr+len), _loopPtr(0), _loopEnd(0), _rate(rate) {
+ : _ptr(ptr), _end(ptr+len), _loopPtr(0), _loopEnd(0), _rate(rate), _playtime(calculatePlayTime(rate, len / (is16Bit ? 2 : 1) / (stereo ? 2 : 1))) {
// Verify the buffer sizes are sane
if (is16Bit && stereo)
@@ -147,10 +153,11 @@ public:
}
int readBuffer(int16 *buffer, const int numSamples);
- bool isStereo() const { return stereo; }
- bool endOfData() const { return _ptr >= _end; }
+ bool isStereo() const { return stereo; }
+ bool endOfData() const { return _ptr >= _end; }
- int getRate() const { return _rate; }
+ int getRate() const { return _rate; }
+ int32 getTotalPlayTime() const { return _playtime; }
};
template<bool stereo, bool is16Bit, bool isUnsigned, bool isLE>
diff --git a/sound/audiostream.h b/sound/audiostream.h
index ed6b37e51c..45740ba2ae 100644
--- a/sound/audiostream.h
+++ b/sound/audiostream.h
@@ -93,6 +93,20 @@ public:
* NULL in case of an error (e.g. invalid/nonexisting file)
*/
static AudioStream* openStreamFile(const Common::String &basename, uint32 startTime = 0, uint32 duration = 0, uint numLoops = 1);
+
+ enum {
+ kUnknownPlayTime = -1
+ };
+
+ /**
+ * Returns total playtime of the AudioStream object.
+ * Note that this does not require to return an playtime, if the
+ * playtime of the AudioStream is unknown it returns 'kUnknownPlayTime'.
+ * @see kUnknownPlayTime
+ *
+ * @return playtime in milliseconds
+ */
+ int32 getTotalPlayTime() const { return kUnknownPlayTime; }
};
/**