Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
pulp::audio::PullRateDetector Class Reference

Detects a host that calls the audio callback faster than real time. More...

#include <pull_rate_detector.hpp>

Public Types

using Clock = std::chrono::steady_clock

Public Member Functions

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 currently pulling faster than real time.
bool fast () const noexcept
double speed () const noexcept
 Audio seconds delivered per wall-clock second over the last full window; 0 until kWindow calls were observed.
void reset () noexcept
 Forget every observation (a new stream: prepare, transport restart).

Static Public Attributes

static constexpr std::size_t kWindow = 8
static constexpr double kEnter = 2.0
static constexpr double kLeave = 1.25

Detailed Description

Detects a host that calls the audio callback faster than real time.

A plug-in that renders on a worker thread (an emulator, offloaded DSP) never waits for the worker on a live callback; it plays whatever the worker has finished. A host that bounces or freezes faster than real time without declaring an offline render therefore gets silence, because the calls arrive back to back and the worker cannot keep up. Feed every callback to observe(); while it returns true the callback may wait for the worker as it would for a declared offline render.

The decision covers the last kWindow calls, so a host that splits one device cycle into several back-to-back calls still averages to real time across cycles. Hysteresis keeps a bounce from flapping: the detector enters above kEnter times real time and leaves below kLeave times.

Realtime safe: arithmetic on a fixed ring, no allocation, no lock. One thread (the audio thread) calls observe().

Member Typedef Documentation

◆ Clock

using pulp::audio::PullRateDetector::Clock = std::chrono::steady_clock

Member Function Documentation

◆ fast()

bool pulp::audio::PullRateDetector::fast ( ) const
inlinenoexcept

◆ observe()

bool pulp::audio::PullRateDetector::observe ( std::size_t frames,
double sample_rate,
Clock::time_point now )
inlinenoexcept

Records one callback of frames at sample_rate that started at now and returns whether the host is currently pulling faster than real time.

◆ reset()

void pulp::audio::PullRateDetector::reset ( )
inlinenoexcept

Forget every observation (a new stream: prepare, transport restart).

◆ speed()

double pulp::audio::PullRateDetector::speed ( ) const
inlinenoexcept

Audio seconds delivered per wall-clock second over the last full window; 0 until kWindow calls were observed.

Member Data Documentation

◆ kEnter

double pulp::audio::PullRateDetector::kEnter = 2.0
staticconstexpr

◆ kLeave

double pulp::audio::PullRateDetector::kLeave = 1.25
staticconstexpr

◆ kWindow

std::size_t pulp::audio::PullRateDetector::kWindow = 8
staticconstexpr

The documentation for this class was generated from the following file: