Class thl::dsp::probe::SampleProbe#
-
class SampleProbe : public thl::dsp::probe::ProbeBase#
Inheritance diagram for thl::dsp::probe::SampleProbe:
Collaboration diagram for thl::dsp::probe::SampleProbe:
Hands the samples it watches to one reader thread: the source of a scope, a spectrum analyser, a goniometer.
observe() copies every block into an SpscRingBuffer (one copy per channel, nothing else on the audio thread). One reader thread drains it with read(), keeps what it needs in a history of its own and does the analysis there.
Discontinuities: wherever the stream is not continuous, the writer marks the position: after a reset() (also the one after the probe was inactive) and where samples were dropped because the reader fell behind. read() skips everything before the newest mark it has not seen and reports it (ReadResult::m_discontinuity): the reader then starts its history over instead of joining samples across the gap.
The ring holds capacity_seconds() at the prepared sample rate (and at least two blocks): a reader at screen rate (16 ms) has plenty of room.
Threads: as ProbeBase (no reader during prepare()); read(), available() and the read position belong to the one reader; dropped() and sample_rate() to any thread.
Public Functions
-
explicit SampleProbe(double capacity_seconds = k_default_capacity_seconds)#
-
virtual void prepare(double sample_rate, size_t max_block_size, size_t num_channels) override#
Control thread: blocks of up to
max_block_sizesamples andnum_channelschannels will come atsample_rate.
-
virtual void reset() override#
Audio thread: marks a discontinuity; the reader skips what came before it.
-
inline double capacity_seconds() const#
-
inline double sample_rate() const#
-
inline size_t num_channels() const#
-
inline size_t capacity() const#
-
ReadResult read(std::span<float*const> channels, size_t num_samples)#
Reader: copies up to
num_samplesof what has arrived, oldest first, intochannels(channels[c]: channel c).After a discontinuity it first skips what came before it.
-
inline size_t available() const#
Reader: the samples that have arrived and not been read (before a discontinuity included).
Public Static Attributes
-
static constexpr double k_default_capacity_seconds = 0.25#
Protected Functions
-
virtual void observe(const thl::core::BufferView &block) override#
Audio thread: what the probe does with a block. Must not change it, allocate or wait.
-
explicit SampleProbe(double capacity_seconds = k_default_capacity_seconds)#