From 03ae98d8a9c9b76a5ee48e2ac64360f12a1e4329 Mon Sep 17 00:00:00 2001 From: lisyarus Date: Fri, 6 Oct 2023 18:57:34 +0300 Subject: [PATCH] Audio::loop fixes --- libs/audio/source/combine/loop.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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; }; }