9 uint32_t clamped_sub(uint32_t a, uint32_t b)
noexcept
11 return a > b ? a - b : 0
U;
19 return "Interval scan thresholds must be finite";
21 if (config.
hop == 0) {
22 return "Interval scan hop must be greater than 0";
25 return "Interval scan run cap must exceed one hop plus twice the padding";
35 std::source_location::current(),
"{}", reason);
38 ? std::numeric_limits<uint32_t>::max()
77 uint32_t padded_start { 0 };
79 const int32_t gap =
static_cast<int32_t
>(start) -
static_cast<int32_t
>(
m_pend_end);
80 if (gap <
static_cast<int32_t
>(2U *
m_config.padding)) {
81 const int32_t half_gap = gap >= 0 ? gap / 2 : -((-gap + 1) / 2);
82 const auto padded_end =
static_cast<uint32_t
>(
static_cast<int32_t
>(
m_pend_end) + half_gap);
83 padded_start = half_gap >= 0
84 ? clamped_sub(start,
static_cast<uint32_t
>(half_gap))
85 : start +
static_cast<uint32_t
>(-half_gap);
89 padded_start = clamped_sub(start,
m_config.padding);
93 padded_start = clamped_sub(start,
m_config.padding);
100std::vector<IntervalScanner::Interval>
IntervalScanner::push(std::span<const double> scores, std::span<const double> gate)
102 if (!gate.empty() && gate.size() != scores.size()) {
104 std::source_location::current(),
"Interval scan gate has {} scores for {} scores", gate.size(), scores.size());
107 const auto first =
static_cast<uint32_t
>(
m_seen);
111 std::vector<Interval> out;
112 const bool gated = !gate.empty();
114 for (
size_t i = 0; i < scores.size(); ++i) {
115 const double score =
static_cast<float>(scores[i]);
116 const uint32_t cur =
m_config.first_sample + (first +
static_cast<uint32_t
>(i)) *
m_config.hop;
117 const bool above = score >=
m_config.enter;
119 if (gated &&
static_cast<double>(
static_cast<float>(gate[i])) <
m_config.gate_threshold) {
134 if (silence >
m_config.gap_at_limit) {
160 const uint32_t resume = cut + dur;
161 if (resume < cut + cur) {
217 std::vector<Interval> out;
Runs of a score sequence that stay above a threshold, found in order as a stream, for MayaFlux::Kines...
IntervalScanConfig m_config
const IntervalScanConfig & config() const noexcept
void reset_gap_state() noexcept
IntervalScanner(const IntervalScanConfig &config)
Construct a scanner.
std::vector< Interval > push(std::span< const double > scores, std::span< const double > gate={})
Continue the stream with more scores.
std::vector< Interval > flush()
End the stream: close the open run and release the pending interval.
void reset() noexcept
Start a new stream without releasing anything.
void close_run(uint32_t start, uint32_t end, std::vector< Interval > &out)
void update_total() noexcept
@ Runtime
General runtime operations (default fallback).
@ Kinesis
General mathematical and physics algorithns.
std::string diagnose_interval_scan(const IntervalScanConfig &config)
Why a config cannot be scanned.
Settings of an IntervalScanner.