aboutsummaryrefslogtreecommitdiff
path: root/sound
diff options
context:
space:
mode:
authorSven Hesse2008-11-16 20:34:31 +0000
committerSven Hesse2008-11-16 20:34:31 +0000
commitb1fa413ed4fe145f0103d279db35e077e8ff9f2f (patch)
tree5bab2a16fda6157fd758317d83cff00f6b1d2f89 /sound
parenta5619194c8e0b7901fdc21a748661e29e7bfa89d (diff)
downloadscummvm-rg350-b1fa413ed4fe145f0103d279db35e077e8ff9f2f.tar.gz
scummvm-rg350-b1fa413ed4fe145f0103d279db35e077e8ff9f2f.tar.bz2
scummvm-rg350-b1fa413ed4fe145f0103d279db35e077e8ff9f2f.zip
Implementing getTotalPlayTime() for AppendableMemoryStream
svn-id: r35098
Diffstat (limited to 'sound')
-rw-r--r--sound/audiostream.cpp17
1 files changed, 15 insertions, 2 deletions
diff --git a/sound/audiostream.cpp b/sound/audiostream.cpp
index 7ba7871bc0..6bc978e575 100644
--- a/sound/audiostream.cpp
+++ b/sound/audiostream.cpp
@@ -263,6 +263,10 @@ protected:
const int _rate;
byte *_pos;
+ // Playing time in milliseconds and rest samples
+ int _playTime;
+ int _playSamp;
+
inline bool eosIntern() const { return _bufferQueue.empty(); };
public:
AppendableMemoryStream(int rate);
@@ -275,13 +279,15 @@ public:
int getRate() const { return _rate; }
+ int32 getTotalPlayTime() const { return _playTime; }
+
void queueBuffer(byte *data, uint32 size);
void finish() { _finalized = true; }
};
template<bool stereo, bool is16Bit, bool isUnsigned, bool isLE>
AppendableMemoryStream<stereo, is16Bit, isUnsigned, isLE>::AppendableMemoryStream(int rate)
- : _finalized(false), _rate(rate), _pos(0) {
+ : _finalized(false), _rate(rate), _pos(0), _playTime(0), _playSamp(0) {
}
@@ -320,7 +326,14 @@ int AppendableMemoryStream<stereo, is16Bit, isUnsigned, isLE>::readBuffer(int16
} while (--len);
}
- return numSamples-samples;
+ int written = numSamples - samples;
+
+ _playSamp += (stereo ? (written / 2) : written);
+
+ _playTime += _playSamp / (_rate / 1000);
+ _playSamp %= (_rate / 1000);
+
+ return written;
}
template<bool stereo, bool is16Bit, bool isUnsigned, bool isLE>