Add audio::mixer::max_length
All checks were successful
Run tests / Run tests (push) Successful in 6m43s
All checks were successful
Run tests / Run tests (push) Successful in 6m43s
This commit is contained in:
parent
99b103b267
commit
506a6c303e
2 changed files with 14 additions and 0 deletions
|
|
@ -15,6 +15,7 @@ namespace psemek::audio
|
||||||
virtual channel_ptr add(stream_ptr stream) = 0;
|
virtual channel_ptr add(stream_ptr stream) = 0;
|
||||||
|
|
||||||
virtual std::size_t stream_count() const = 0;
|
virtual std::size_t stream_count() const = 0;
|
||||||
|
virtual std::size_t max_length() const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
using mixer_ptr = std::shared_ptr<mixer>;
|
using mixer_ptr = std::shared_ptr<mixer>;
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,8 @@ namespace psemek::audio
|
||||||
return stream_count_.load();
|
return stream_count_.load();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::size_t max_length() const override;
|
||||||
|
|
||||||
std::size_t read(util::span<float> samples) override;
|
std::size_t read(util::span<float> samples) override;
|
||||||
|
|
||||||
std::optional<std::size_t> length() const override
|
std::optional<std::size_t> length() const override
|
||||||
|
|
@ -59,6 +61,17 @@ namespace psemek::audio
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::size_t mixer_impl::max_length() const
|
||||||
|
{
|
||||||
|
// TODO: safe access when the mixer is already playing?
|
||||||
|
std::size_t result = 0;
|
||||||
|
for (auto const & channel : new_channels_)
|
||||||
|
if (auto stream = channel->stream())
|
||||||
|
if (auto length = stream->length(); length && *length > result)
|
||||||
|
result = *length;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
std::size_t mixer_impl::read(util::span<float> samples)
|
std::size_t mixer_impl::read(util::span<float> samples)
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue