MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ push()

std::vector< IntervalScanner::Interval > MayaFlux::Kinesis::Discrete::IntervalScanner::push ( std::span< const double > scores,
std::span< const double > gate = {} )
nodiscard

Continue the stream with more scores.

Parameters
scoresScores in order
gateOne gate score per score, or empty for no gate
Returns
The half open intervals completed by this call, in order
Exceptions
std::invalid_argumentWhen gate is not empty and its length differs from the scores

Definition at line 100 of file IntervalScan.cpp.

101{
102 if (!gate.empty() && gate.size() != scores.size()) {
103 error<std::invalid_argument>(Journal::Component::Kinesis, Journal::Context::Runtime,
104 std::source_location::current(), "Interval scan gate has {} scores for {} scores", gate.size(), scores.size());
105 }
106
107 const auto first = static_cast<uint32_t>(m_seen);
108 m_seen += scores.size();
109 update_total();
110
111 std::vector<Interval> out;
112 const bool gated = !gate.empty();
113
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;
118
119 if (gated && static_cast<double>(static_cast<float>(gate[i])) < m_config.gate_threshold) {
120 if (m_triggered) {
121 const uint32_t end = m_temp_end != 0 ? m_temp_end : cur;
122 if (end > m_start && end - m_start > m_config.min_run) {
123 close_run(m_start, end, out);
124 }
125 }
126 m_has_start = false;
127 m_triggered = false;
129 continue;
130 }
131
132 if (above && m_temp_end != 0) {
133 const uint32_t silence = cur - m_temp_end;
134 if (silence > m_config.gap_at_limit) {
135 if (!m_has_best || silence > m_best_dur) {
137 m_best_dur = silence;
138 m_has_best = true;
139 }
140 }
141 m_temp_end = 0;
142 if (m_next_start < m_prev_end) {
143 m_next_start = cur;
144 }
145 }
146
147 if (above && !m_triggered) {
148 m_triggered = true;
149 m_start = cur;
150 m_has_start = true;
151 continue;
152 }
153
154 if (m_triggered && cur > m_start && cur - m_start > m_run_limit) {
155 if (m_config.use_longest_gap && m_has_best) {
156 const uint32_t cut = m_best_end;
157 const uint32_t dur = m_best_dur;
158 close_run(m_start, cut, out);
159 m_has_start = false;
160 const uint32_t resume = cut + dur;
161 if (resume < cut + cur) {
162 m_start = resume;
163 m_has_start = true;
164 } else {
165 m_triggered = false;
166 }
168 } else if (m_prev_end != 0) {
169 const uint32_t cut = m_prev_end;
170 close_run(m_start, cut, out);
171 m_has_start = false;
172 if (m_next_start < cut) {
173 m_triggered = false;
174 } else {
176 m_has_start = true;
177 }
179 } else {
180 close_run(m_start, cur, out);
181 m_has_start = false;
183 m_triggered = false;
184 continue;
185 }
186 }
187
188 if (score < m_config.leave && m_triggered) {
189 if (m_temp_end == 0) {
190 m_temp_end = cur;
191 }
192 const uint32_t quiet = cur - m_temp_end;
193
194 if (!m_config.use_longest_gap && quiet > m_config.gap_at_limit) {
196 }
197 if (quiet < m_config.min_gap) {
198 continue;
199 }
200
201 const uint32_t end = m_temp_end;
202 if (end > m_start && end - m_start > m_config.min_run) {
203 close_run(m_start, end, out);
204 }
205 m_has_start = false;
206 m_triggered = false;
208 }
209 }
210
211 return out;
212}
void close_run(uint32_t start, uint32_t end, std::vector< Interval > &out)
@ Runtime
General runtime operations (default fallback).
@ Kinesis
General mathematical and physics algorithns.

References close_run(), MayaFlux::Journal::Kinesis, m_best_dur, m_best_end, m_config, m_has_best, m_has_start, m_next_start, m_prev_end, m_run_limit, m_seen, m_start, m_temp_end, m_triggered, reset_gap_state(), MayaFlux::Journal::Runtime, and update_total().

Here is the call graph for this function: