aboutsummaryrefslogtreecommitdiff
path: root/sound/audiostream.cpp
diff options
context:
space:
mode:
authorJohannes Schickel2010-01-01 16:57:23 +0000
committerJohannes Schickel2010-01-01 16:57:23 +0000
commitbba2c8ce952b5242e3ff80054f1ac9cc48bcd097 (patch)
tree3a62d52c8ea2d92d7eefb9ed7e0a3698b4685f2b /sound/audiostream.cpp
parent54d9bf4c57d265dd0d0539ed5eb0bfe324427ea7 (diff)
downloadscummvm-rg350-bba2c8ce952b5242e3ff80054f1ac9cc48bcd097.tar.gz
scummvm-rg350-bba2c8ce952b5242e3ff80054f1ac9cc48bcd097.tar.bz2
scummvm-rg350-bba2c8ce952b5242e3ff80054f1ac9cc48bcd097.zip
Fix getTotalPlayTime for MP3, FLAC, Vorbis and LinearMemoryStream after the latest loop related changes.
svn-id: r46838
Diffstat (limited to 'sound/audiostream.cpp')
-rw-r--r--sound/audiostream.cpp18
1 files changed, 15 insertions, 3 deletions
diff --git a/sound/audiostream.cpp b/sound/audiostream.cpp
index 2915b38eec..795953c3a8 100644
--- a/sound/audiostream.cpp
+++ b/sound/audiostream.cpp
@@ -138,8 +138,11 @@ public:
: _ptr(ptr), _end(ptr+len), _loopPtr(0), _loopEnd(0), _rate(rate), _playtime(calculatePlayTime(rate, len / (is16Bit ? 2 : 1) / (stereo ? 2 : 1))) {
if (loopLen) {
+ _numLoops = 0;
_loopPtr = _ptr + loopOffset;
_loopEnd = _loopPtr + loopLen;
+ } else {
+ _numLoops = 1;
}
_origPtr = autoFreeMemory ? ptr : 0;
@@ -153,7 +156,11 @@ public:
bool endOfData() const { return _ptr >= _end; }
int getRate() const { return _rate; }
- int32 getTotalPlayTime() const { return _playtime; }
+ int32 getTotalPlayTime() const {
+ if (!_numLoops)
+ return kUnknownPlayTime;
+ return _playtime * _numLoops;
+ }
void setNumLoops(uint numLoops) {
_numLoops = numLoops;
@@ -181,6 +188,7 @@ int LinearMemoryStream<stereo, is16Bit, isUnsigned, isLE>::readBuffer(int16 *buf
_ptr += (is16Bit ? 2 : 1);
} while (--len);
// Loop, if looping was specified
+ // TODO: Handle non-infinite loops
if (_loopPtr && _ptr >= _end) {
_ptr = _loopPtr;
_end = _loopEnd;
@@ -242,7 +250,7 @@ protected:
public:
LinearDiskStream(int rate, uint beginLoop, uint endLoop, bool disposeStream, Common::SeekableReadStream *stream, LinearDiskStreamAudioBlock *block, uint numBlocks, bool loop)
: _rate(rate), _stream(stream), _beginLoop(beginLoop), _endLoop(endLoop), _disposeAfterUse(disposeStream),
- _audioBlockCount(numBlocks), _loop(loop), _numPlayedLoops(0) {
+ _audioBlockCount(numBlocks), _loop(loop), _numLoops(loop ? 0 : 1), _numPlayedLoops(0) {
assert(numBlocks > 0);
@@ -290,7 +298,11 @@ public:
bool endOfData() const { return (_currentBlock == _audioBlockCount - 1) && (_diskLeft == 0) && (_bufferLeft == 0); }
int getRate() const { return _rate; }
- int32 getTotalPlayTime() const { return _playtime; }
+ int32 getTotalPlayTime() const {
+ if (!_numLoops)
+ return kUnknownPlayTime;
+ return _playtime * _numLoops;
+ }
};
template<bool stereo, bool is16Bit, bool isUnsigned, bool isLE>