aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Schickel2010-01-07 20:13:02 +0000
committerJohannes Schickel2010-01-07 20:13:02 +0000
commita15cc002bbbba1666cde6b12daa72edb40ef2e89 (patch)
tree42a40828e8de0a9f88cda032da731dbee549648a
parentbd651c6c3d85bc4561fcd0a80492127ec359f894 (diff)
downloadscummvm-rg350-a15cc002bbbba1666cde6b12daa72edb40ef2e89.tar.gz
scummvm-rg350-a15cc002bbbba1666cde6b12daa72edb40ef2e89.tar.bz2
scummvm-rg350-a15cc002bbbba1666cde6b12daa72edb40ef2e89.zip
Cleanup.
svn-id: r47139
-rw-r--r--sound/audiostream.cpp15
-rw-r--r--sound/audiostream.h3
2 files changed, 12 insertions, 6 deletions
diff --git a/sound/audiostream.cpp b/sound/audiostream.cpp
index 701b7e50ff..f16011ce52 100644
--- a/sound/audiostream.cpp
+++ b/sound/audiostream.cpp
@@ -149,8 +149,10 @@ AudioStream *makeLoopingAudioStream(RewindableAudioStream *stream, uint loops) {
#pragma mark -
SubSeekableAudioStream::SubSeekableAudioStream(SeekableAudioStream *parent, const Timestamp start, const Timestamp end, bool disposeAfterUse)
- : _parent(parent), _disposeAfterUse(disposeAfterUse), _isStereo(parent->isStereo()),
- _start(start.convertToFramerate(getRate())), _pos(0, getRate()), _length(end.convertToFramerate(getRate())) {
+ : _parent(parent), _disposeAfterUse(disposeAfterUse),
+ _start(start.convertToFramerate(getRate())),
+ _pos(0, getRate() * (isStereo() ? 2 : 1)),
+ _length(end.convertToFramerate(getRate())) {
// TODO: This really looks like Timestamp::operator-
_length = Timestamp(_length.secs() - _start.secs(), _length.numberOfFrames() - _start.numberOfFrames(), getRate());
_parent->seek(_start);
@@ -162,14 +164,19 @@ SubSeekableAudioStream::~SubSeekableAudioStream() {
}
int SubSeekableAudioStream::readBuffer(int16 *buffer, const int numSamples) {
- int framesLeft = MIN(_length.frameDiff(_pos) * (_isStereo ? 2 : 1), numSamples);
+ int framesLeft = MIN(_length.frameDiff(_pos), numSamples);
int framesRead = _parent->readBuffer(buffer, framesLeft);
- _pos = _pos.addFrames(framesRead / (_isStereo ? 2 : 1));
+ _pos = _pos.addFrames(framesRead);
return framesRead;
}
bool SubSeekableAudioStream::seek(const Timestamp &where) {
_pos = where.convertToFramerate(getRate());
+ if (_pos > _length) {
+ _pos = _length;
+ return false;
+ }
+
// TODO: This really looks like Timestamp::operator+
if (_parent->seek(Timestamp(_pos.secs() + _start.secs(), _pos.numberOfFrames() + _start.numberOfFrames(), getRate()))) {
return true;
diff --git a/sound/audiostream.h b/sound/audiostream.h
index 7c84a4cea6..85807e8134 100644
--- a/sound/audiostream.h
+++ b/sound/audiostream.h
@@ -223,7 +223,7 @@ public:
int readBuffer(int16 *buffer, const int numSamples);
- bool isStereo() const { return _isStereo; }
+ bool isStereo() const { return _parent->isStereo(); }
int getRate() const { return _parent->getRate(); }
@@ -235,7 +235,6 @@ public:
private:
SeekableAudioStream *_parent;
bool _disposeAfterUse;
- const bool _isStereo;
const Timestamp _start;
Timestamp _pos, _length;