Fix length computation in truncate filter
This commit is contained in:
parent
3713f620bb
commit
dbf5117dc6
1 changed files with 9 additions and 6 deletions
|
|
@ -13,19 +13,21 @@ namespace psemek::audio
|
|||
{
|
||||
truncate_impl(stream_ptr stream, duration length)
|
||||
: stream_(std::move(stream))
|
||||
, length_(length)
|
||||
, remaining_(length.samples())
|
||||
, total_length_(stream_->played() + remaining_)
|
||||
{}
|
||||
|
||||
std::optional<std::size_t> length() const override
|
||||
{
|
||||
return length_.samples();
|
||||
return total_length_;
|
||||
}
|
||||
|
||||
std::size_t read(util::span<float> samples) override
|
||||
{
|
||||
auto played = stream_->played();
|
||||
auto max_count = std::min<std::size_t>(length_.samples() - played, samples.size());
|
||||
return stream_->read(samples.prefix(max_count));
|
||||
auto const max_count = std::min<std::size_t>(remaining_, samples.size());
|
||||
auto const count = stream_->read(samples.prefix(max_count));
|
||||
remaining_ -= count;
|
||||
return count;
|
||||
}
|
||||
|
||||
std::size_t played() const override
|
||||
|
|
@ -35,7 +37,8 @@ namespace psemek::audio
|
|||
|
||||
private:
|
||||
stream_ptr stream_;
|
||||
duration length_;
|
||||
std::size_t remaining_;
|
||||
std::size_t total_length_;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue