Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
latency_evidence.hpp
Go to the documentation of this file.
1#pragma once
2
45
47#include <pulp/audio/buffer.hpp>
48
49#include <cstdint>
50#include <optional>
51#include <string>
52
53namespace pulp::test::audio {
54
62
69
76
90
98
106
109 // ── Facts read from the processor / host ────────────────────────────────
113 std::optional<int> reported_samples;
115 std::optional<int> final_reported_samples;
118
119 // ── The measurement ─────────────────────────────────────────────────────
123 std::optional<std::int64_t> measured_samples;
125 std::optional<std::int64_t> delta_samples;
127 std::int64_t tolerance_samples = 0;
128
129 // ── How much to trust the measurement ───────────────────────────────────
130 //
131 // Both are populated by the delayed-null policy only; the marker policy
132 // finds an onset rather than nulling, so neither number exists for it.
133 //
134 // They are the difference between "the measurement passed" and "the
135 // measurement passed, and here is how far it was from being a coin flip."
136 // An agent reading the artifact should treat a 2 dB margin as a hair's
137 // breadth from ambiguous even though it technically cleared the bar.
138
143 std::optional<double> null_depth_db;
144
150 std::optional<double> ambiguity_margin_db;
151
163 std::optional<int> expected_samples;
164
165 // ── The verdict ─────────────────────────────────────────────────────────
169 std::string reason;
170
179};
180
187 std::int64_t max_delay_samples = 8192;
192 double null_floor_db = -60.0;
196 double ambiguity_margin_db = 12.0;
198 std::int64_t tolerance_samples = 0;
199};
200
214 const pulp::audio::Buffer<float>& output,
215 std::optional<int> reported_samples,
216 const DelayedNullOptions& options = {});
217
222 std::int64_t input_marker_frame = 0;
228 double onset_threshold = 1e-3;
229 std::int64_t tolerance_samples = 0;
230};
231
240 const pulp::audio::Buffer<float>& output,
241 std::optional<int> reported_samples,
242 const MarkerOffsetOptions& options = {});
243
252
260 std::int64_t tolerance_samples = 0);
261
262// ── Serialization ───────────────────────────────────────────────────────────
263// One schema, shared by tests, the CLI, and MCP, so a verdict cannot drift
264// between surfaces.
265
266const char* to_string(LatencyReportStatus status);
267const char* to_string(LatencyReportObservation observation);
269const char* to_string(LatencyPolicy policy);
272
274inline constexpr int kLatencyEvidenceSchemaVersion = 1;
275
277std::string latency_evidence_to_json(const LatencyEvidence& evidence);
278
281std::string latency_evidence_summary(const LatencyEvidence& evidence);
282
283} // namespace pulp::test::audio
Deterministic offline signal metrics for rendered audio buffers.
Owning multi-channel audio buffer with contiguous storage.
Definition buffer.hpp:119
Definition audio_artifacts.hpp:20
LatencyObservationMode
How the report was watched while the render ran.
Definition latency_evidence.hpp:71
@ per_block_poll
Hosted slot: poll between blocks (no flag surface).
Definition latency_evidence.hpp:73
@ processor_flag_and_poll
Direct Processor: poll + the latency-changed flag.
Definition latency_evidence.hpp:72
@ none
Not watched.
Definition latency_evidence.hpp:74
constexpr int kLatencyEvidenceSchemaVersion
Schema version of the emitted object. Bump on any breaking field change.
Definition latency_evidence.hpp:274
LatencyReportObservation
Whether the report held still for the duration of the render.
Definition latency_evidence.hpp:64
@ unobservable
The surface offers no way to watch it.
Definition latency_evidence.hpp:67
@ changed
The value moved, or a change was flagged, mid-render.
Definition latency_evidence.hpp:66
@ stable
Same value at every observation point.
Definition latency_evidence.hpp:65
LatencyReportStatus
Whether a latency report could be read at all, and whether it was sane.
Definition latency_evidence.hpp:56
@ query_failed
The query was attempted and errored.
Definition latency_evidence.hpp:59
@ unsupported
This format/host cannot expose latency. NOT a zero.
Definition latency_evidence.hpp:58
@ available
A value was read. It may legitimately be zero.
Definition latency_evidence.hpp:57
@ invalid
A value was read but is nonsensical (e.g. negative).
Definition latency_evidence.hpp:60
std::string latency_evidence_summary(const LatencyEvidence &evidence)
One-line human summary, suitable for a test failure message.
const char * to_string(LatencyReportStatus status)
LatencyPolicy
The probe used to turn audio into a delay measurement.
Definition latency_evidence.hpp:78
@ marker_offset
The author declares a unique input marker and any intrinsic response offset (e.g.
Definition latency_evidence.hpp:88
@ none
Definition latency_evidence.hpp:79
@ delayed_passthrough_null
Compare the output against the input delayed by D, sweeping D.
Definition latency_evidence.hpp:84
LatencyMeasurementStatus
What the probe concluded.
Definition latency_evidence.hpp:92
@ mismatch
Measured delay disagrees with the report.
Definition latency_evidence.hpp:94
@ not_measurable
The response cannot pin a delay down. See reason.
Definition latency_evidence.hpp:95
@ not_requested
No measurement was asked for.
Definition latency_evidence.hpp:96
@ match
Measured delay agrees with the report, within tolerance.
Definition latency_evidence.hpp:93
LatencyEvidence measure_delayed_passthrough(const pulp::audio::Buffer< float > &input, const pulp::audio::Buffer< float > &output, std::optional< int > reported_samples, const DelayedNullOptions &options={})
Sweep the delay D that best explains output as a copy of input, and compare it against reported_sampl...
LatencyEvidence & apply_report_observation(LatencyEvidence &evidence)
Fold a report-observation fact into already-measured evidence.
LatencyEvidence measure_marker_offset(const pulp::audio::Buffer< float > &input, const pulp::audio::Buffer< float > &output, std::optional< int > reported_samples, const MarkerOffsetOptions &options={})
Measure delay as output_onset - input_marker - intrinsic_response_offset and compare it against repor...
LatencyContractOutcome
The gating verdict.
Definition latency_evidence.hpp:100
@ satisfied
Proven: the report matches the audio.
Definition latency_evidence.hpp:101
@ not_requested
Neutral — nothing was claimed, so nothing failed.
Definition latency_evidence.hpp:104
@ inconclusive
A measurement was requested but could not be drawn.
Definition latency_evidence.hpp:103
@ violated
Disproven: they disagree.
Definition latency_evidence.hpp:102
LatencyEvidence & apply_expected_samples(LatencyEvidence &evidence, int expected, std::int64_t tolerance_samples=0)
Additionally require the latency to equal expected, pinning the value rather than only its self-consi...
std::string latency_evidence_to_json(const LatencyEvidence &evidence)
Serialize evidence to a JSON object string.
Knobs for measure_delayed_passthrough.
Definition latency_evidence.hpp:184
double null_floor_db
The residual at the best delay must be at least this far below the input level for the output to coun...
Definition latency_evidence.hpp:192
double ambiguity_margin_db
The best delay must beat every non-adjacent competing delay by at least this margin.
Definition latency_evidence.hpp:196
std::int64_t max_delay_samples
Largest delay considered, in samples.
Definition latency_evidence.hpp:187
std::int64_t tolerance_samples
|measured - reported| may not exceed this and still be a match.
Definition latency_evidence.hpp:198
One processor's latency evidence: the facts, the measurement, the verdict.
Definition latency_evidence.hpp:108
std::string reason
Why the outcome is inconclusive, or why the measurement was not possible.
Definition latency_evidence.hpp:169
bool gates_failure() const
True when the evidence must fail a gate: a disproven report, or a measurement that was asked for and ...
Definition latency_evidence.hpp:175
std::int64_t tolerance_samples
How far |delta| may stray and still count as a match.
Definition latency_evidence.hpp:127
LatencyObservationMode observation_mode
Definition latency_evidence.hpp:117
std::optional< double > ambiguity_margin_db
How much worse the best COMPETING delay nulled, in dB — the winner's margin of victory.
Definition latency_evidence.hpp:150
std::optional< int > expected_samples
An optional INTENDED latency, independent of what the processor reports.
Definition latency_evidence.hpp:163
LatencyReportObservation report_observation
Definition latency_evidence.hpp:116
LatencyPolicy policy
Definition latency_evidence.hpp:120
LatencyMeasurementStatus measurement_status
Definition latency_evidence.hpp:121
std::optional< std::int64_t > measured_samples
The delay actually observed in the audio, in samples.
Definition latency_evidence.hpp:123
std::optional< double > null_depth_db
Residual level at the winning delay, relative to the input, in dB.
Definition latency_evidence.hpp:143
LatencyContractOutcome contract_outcome
Definition latency_evidence.hpp:166
std::optional< int > reported_samples
The report at the start of the render.
Definition latency_evidence.hpp:113
std::optional< std::int64_t > delta_samples
measured - reported. Null unless both are known.
Definition latency_evidence.hpp:125
LatencyReportStatus report_status
Definition latency_evidence.hpp:110
std::optional< int > final_reported_samples
The report at the end of the render, when observable.
Definition latency_evidence.hpp:115
Knobs for measure_marker_offset.
Definition latency_evidence.hpp:219
double onset_threshold
|sample| at or above this linear level counts as the onset.
Definition latency_evidence.hpp:228
std::int64_t intrinsic_response_offset
Delay the processor adds for reasons other than latency — e.g.
Definition latency_evidence.hpp:226
std::int64_t input_marker_frame
Frame of the marker in the input.
Definition latency_evidence.hpp:222
std::int64_t tolerance_samples
Definition latency_evidence.hpp:229