From a15cc002bbbba1666cde6b12daa72edb40ef2e89 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Thu, 7 Jan 2010 20:13:02 +0000 Subject: Cleanup. svn-id: r47139 --- sound/audiostream.cpp | 15 +++++++++++---- sound/audiostream.h | 3 +-- 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; -- cgit v1.2.3