Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
audio_probe.hpp
Go to the documentation of this file.
1#pragma once
2
22
25#include <pulp/audio/buffer.hpp>
28
29#include <cstdint>
30#include <memory>
31#include <vector>
32
33namespace pulp::audio {
34
45
54public:
55 AudioProbe() = default;
56
59
71 int max_frames,
72 double sample_rate,
74 CaptureConfig capture = {});
75
81 void analyze_output(const BufferView<const float>& output) noexcept;
82
85 AudioProbeSnapshot latest() { return summary_buf_.read(); }
86
91
97 int read_capture(float* dst, int max_frames);
98
104
107 void reset() noexcept;
108
109 int max_channels() const noexcept { return max_channels_; }
110 int max_frames() const noexcept { return max_frames_; }
111 bool capture_enabled() const noexcept { return capture_frames_ > 0; }
112
115 void set_silence_threshold(float linear) noexcept { silence_threshold_ = linear; }
117 void set_clip_ceiling(float linear) noexcept { clip_ceiling_ = linear; }
118
119private:
120 void publish_empty_snapshot() noexcept;
121
122 int max_channels_ = 0;
123 int max_frames_ = 0;
124 int capture_frames_ = 0;
125 double sample_rate_ = 0.0;
127
128 float silence_threshold_ = 3.1622776e-5f; // ~ -90 dBFS
129 float clip_ceiling_ = 1.0f;
130
131 std::uint64_t sequence_number_ = 0;
132 std::uint64_t clip_count_ = 0; // per-sample
133 std::uint64_t nan_inf_count_ = 0; // per-sample
134 std::uint64_t clipped_blocks_ = 0; // per-block: blocks with >=1 clip
135 std::uint64_t nan_blocks_ = 0; // per-block: blocks with >=1 NaN/Inf
136 std::uint64_t callbacks_ = 0;
137 std::uint64_t silence_run_blocks_ = 0;
138 std::uint64_t dropped_capture_frames_ = 0;
139
140 runtime::TripleBuffer<AudioProbeSnapshot> summary_buf_;
141
142 // Optional last-N capture: SpscRingIndex over preallocated, probe-owned
143 // storage. The FIFO indexes frames; storage is channel-major with
144 // `capture_storage_channels_` lanes, each `capture_frames_ + 1` samples
145 // long. The ring is sized at prepare(); analyze_output() never resizes it.
146 std::vector<float> capture_storage_;
147 int capture_storage_channels_ = 0;
148 std::unique_ptr<runtime::SpscRingIndex> capture_fifo_;
149};
150
151} // namespace pulp::audio
The realtime-produced probe summary — the shared schema between the RT producer (pulp::audio::AudioPr...
Small POD counter struct for release-safe audio observability.
void reset() noexcept
Reset all cumulative counters and the capture ring.
int read_capture(BufferView< float > dst, int max_frames)
Copy up to max_frames of the most recent captured multichannel history into dst (UI/worker thread).
AudioProbeCaptureConfig CaptureConfig
Configuration for the optional last-N-frames capture ring.
Definition audio_probe.hpp:58
void prepare(int max_channels, int max_frames, double sample_rate, AudioProbeStage stage=AudioProbeStage::kStandaloneOutputBoundary, CaptureConfig capture={})
Allocate fixed-capacity storage.
void set_silence_threshold(float linear) noexcept
Silence threshold (linear).
Definition audio_probe.hpp:115
AudioProbeSnapshot latest()
Read the latest published snapshot (UI/worker thread).
Definition audio_probe.hpp:85
int max_frames() const noexcept
Definition audio_probe.hpp:110
int read_capture(float *dst, int max_frames)
Copy up to max_frames of the most recent captured channel-0 history into dst (UI/worker thread).
void analyze_output(const BufferView< const float > &output) noexcept
Realtime-safe per-block analysis.
AudioStats stats()
Release-safe counter subset, derived from the latest snapshot.
int max_channels() const noexcept
Definition audio_probe.hpp:109
void set_clip_ceiling(float linear) noexcept
Clip ceiling (linear). Samples with |x| strictly greater are "clipped".
Definition audio_probe.hpp:117
bool capture_enabled() const noexcept
Definition audio_probe.hpp:111
Non-owning view over multi-channel audio sample data.
Definition buffer.hpp:30
Definition analyzer_provider.hpp:12
AudioProbeStage
Identifies which audio boundary a snapshot was produced at.
Definition audio_probe_snapshot.hpp:28
@ kUnknown
Definition audio_probe_snapshot.hpp:29
@ kStandaloneOutputBoundary
Definition audio_probe_snapshot.hpp:31
Definition generated_event_source.hpp:33
STL namespace.
Configuration for the optional last-N-frames capture ring.
Definition audio_probe.hpp:41
int capture_frames
Frames-per-channel of history to retain. 0 disables capture.
Definition audio_probe.hpp:43
Realtime-produced, fixed-capacity, trivially-copyable probe summary.
Definition audio_probe_snapshot.hpp:42
Minimal release-safe audio counter aggregate.
Definition audio_stats.hpp:36
Lock-free latest-value publication between two threads.