diff --git a/libs/audio/source/combine/loop.cpp b/libs/audio/source/combine/loop.cpp index 5804c76f..e90926d6 100644 --- a/libs/audio/source/combine/loop.cpp +++ b/libs/audio/source/combine/loop.cpp @@ -18,8 +18,8 @@ namespace psemek::audio std::optional length() const override { - if (count_) - return (*stream_->length()) * (*count_); + if (auto length = stream_->length(); length && count_) + return (*length) * (*count_); return std::nullopt; } @@ -34,6 +34,7 @@ namespace psemek::audio if (scount < need) { ++repeated_; + cached_length_ = stream_->played(); stream_ = dup_->stream(); } } @@ -42,7 +43,7 @@ namespace psemek::audio std::size_t played() const override { - return stream_->played() + (*stream_->length()) * repeated_; + return stream_->played() + cached_length_ * repeated_; } private: @@ -50,6 +51,7 @@ namespace psemek::audio stream_ptr stream_; std::optional count_; std::size_t repeated_ = 0; + std::size_t cached_length_ = 0; }; }