31 using Clock = std::chrono::steady_clock;
33 static constexpr double kEnter = 2.0;
34 static constexpr double kLeave = 1.25;
38 bool observe(std::size_t frames,
double sample_rate, Clock::time_point now)
noexcept {
39 calls_[next_ %
kWindow] = {now, frames};
41 if (next_ <
kWindow || !(sample_rate > 0.0))
45 const auto& oldest = calls_[next_ %
kWindow];
46 std::size_t newer_frames = 0;
47 for (std::size_t i = 1; i <
kWindow; ++i)
48 newer_frames += calls_[(next_ + i) %
kWindow].frames;
49 const double audio_s =
static_cast<double>(newer_frames) / sample_rate;
50 const double wall_s = std::chrono::duration<double>(now - oldest.time).count();
51 speed_ = wall_s > 0.0 ? audio_s / wall_s :
kEnter * 1000.0;
56 bool fast() const noexcept {
74 Clock::time_point time{};
75 std::size_t frames = 0;
77 std::array<Call, kWindow> calls_{};
78 std::size_t next_ = 0;
Detects a host that calls the audio callback faster than real time.
Definition pull_rate_detector.hpp:29
static constexpr std::size_t kWindow
Definition pull_rate_detector.hpp:32
static constexpr double kLeave
Definition pull_rate_detector.hpp:34
bool observe(std::size_t frames, double sample_rate, Clock::time_point now) noexcept
Records one callback of frames at sample_rate that started at now and returns whether the host is cur...
Definition pull_rate_detector.hpp:38
bool fast() const noexcept
Definition pull_rate_detector.hpp:56
void reset() noexcept
Forget every observation (a new stream: prepare, transport restart).
Definition pull_rate_detector.hpp:66
std::chrono::steady_clock Clock
Definition pull_rate_detector.hpp:31
double speed() const noexcept
Audio seconds delivered per wall-clock second over the last full window; 0 until kWindow calls were o...
Definition pull_rate_detector.hpp:61
static constexpr double kEnter
Definition pull_rate_detector.hpp:33
Definition analyzer_provider.hpp:12