Audio::loop fixes

This commit is contained in:
Nikita Lisitsa 2023-10-06 18:57:34 +03:00
parent 52b18c07a4
commit 03ae98d8a9

View file

@ -18,8 +18,8 @@ namespace psemek::audio
std::optional<std::size_t> 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<std::size_t> count_;
std::size_t repeated_ = 0;
std::size_t cached_length_ = 0;
};
}