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

◆ process_mapped()

void MayaFlux::Kakshya::CursorAccessProcessor::process_mapped ( DynamicSoundStream &  stream,
std::vector< DataVariant > &  pd 
)
private

Definition at line 144 of file CursorAccessProcessor.cpp.

145{
146 const uint64_t block = m_frames_per_block;
147 const uint64_t channels = m_structure.get_channel_count();
149
150 const auto rate = static_cast<double>(stream.get_sample_rate());
151 const auto lo = static_cast<double>(m_loop_start);
152 const auto hi = static_cast<double>(m_loop_end);
153 m_gather_frames.resize(2 * block);
154 m_gather_weights.resize(block);
155
156 const bool repeating = m_repeat && m_repeat->fn;
157 bool exited = m_loop_end <= m_loop_start;
158 double last_position = lo;
159 uint64_t valid = 0;
160
161 while (!exited && valid < block) {
162 const uint64_t clock = m_clock_frames + valid;
163 uint64_t stop = block;
164
165 if (repeating) {
166 if (m_repeat_length == 0 || clock - m_repeat_start >= m_repeat_length) {
167 m_repeat_start = clock;
168 const double seconds = std::max((*m_repeat)(static_cast<double>(clock) / rate), 0.0);
169 m_repeat_length = std::max<uint64_t>(1, static_cast<uint64_t>(std::llround(seconds * rate)));
170 }
171
172 stop = std::min(block, valid + (m_repeat_start + m_repeat_length - clock));
173 }
174
175 const uint64_t origin = repeating ? m_repeat_start : 0;
176 const uint64_t begin = valid;
177 const uint64_t frames = stop - begin;
178 const auto span = static_cast<double>(frames);
179 const double p_a = (*m_time_map)(static_cast<double>(clock - origin) / rate);
180 const double p_b = (*m_time_map)(static_cast<double>(clock + frames - origin) / rate);
181 last_position = p_b;
182
183 for (; valid < stop; ++valid) {
184 const double u = p_a + (p_b - p_a) * static_cast<double>(valid - begin) / span;
185
186 if (!m_looping && (u < lo || u >= hi)) {
187 exited = true;
188 break;
189 }
190
191 const double s = m_looping ? Kinesis::wrap<double>(u, lo, hi) : u;
192 const double whole = std::floor(s);
193 const uint64_t i = std::min(static_cast<uint64_t>(whole), m_loop_end - 1);
194 const uint64_t next = i + 1 < m_loop_end ? i + 1 : (m_looping ? m_loop_start : i);
195
196 m_gather_frames[2 * valid] = i;
197 m_gather_frames[2 * valid + 1] = next;
198 m_gather_weights[valid] = s - whole;
199 }
200 }
201
202 m_gather_taps.resize(2 * block * channels);
203 stream.gather_frames(
204 std::span<const uint64_t>(m_gather_frames.data(), 2 * valid),
205 std::span<double>(m_gather_taps.data(), 2 * valid * channels));
206
207 const auto blend = [&](uint64_t n, uint64_t c) {
208 const double w = m_gather_weights[n];
209 return m_gather_taps[(2 * n) * channels + c] * (1.0 - w)
210 + m_gather_taps[(2 * n + 1) * channels + c] * w;
211 };
212
213 if (interleaved) {
214 pd.resize(1);
215 auto& out = std::get<std::vector<double>>(pd[0]);
216 out.assign(block * channels, 0.0);
217 for (uint64_t n = 0; n < valid; ++n) {
218 for (uint64_t c = 0; c < channels; ++c) {
219 out[n * channels + c] = blend(n, c);
220 }
221 }
222 } else {
223 pd.resize(channels);
224 for (uint64_t c = 0; c < channels; ++c) {
225 auto& out = std::get<std::vector<double>>(pd[c]);
226 out.assign(block, 0.0);
227 for (uint64_t n = 0; n < valid; ++n) {
228 out[n] = blend(n, c);
229 }
230 }
231 }
232
233 m_clock_frames += block;
234
235 if (exited) {
236 m_active = false;
237 m_clock_frames = 0;
238 m_cursor.assign(m_cursor.size(), m_loop_start);
239 if (m_on_end)
240 m_on_end();
241 return;
242 }
243
244 const double end = m_looping ? Kinesis::wrap<double>(last_position, lo, hi) : std::clamp(last_position, lo, hi - 1.0);
245 m_cursor.assign(m_cursor.size(), static_cast<uint64_t>(std::max(end, lo)));
246}
Core::GlobalStreamInfo stream
Definition Config.cpp:40
float rate
std::vector< float > * out
uint32_t channels
void stop()
Deactivate without resetting the cursor position.
std::shared_ptr< const Kinesis::TimeMap > m_repeat
@ INTERLEAVED
Single DataVariant with interleaved data (LRLRLR for stereo)
void clamp(std::span< double > data, double lo, double hi) noexcept
Clamp values to [lo, hi] in-place.
Definition Transform.cpp:44
static uint64_t get_channel_count(const std::vector< DataDimension > &dimensions)
Extract channel count from dimensions.

References channels, MayaFlux::Kakshya::ContainerDataStructure::get_channel_count(), MayaFlux::Kakshya::INTERLEAVED, m_active, m_clock_frames, m_cursor, m_frames_per_block, m_gather_frames, m_gather_taps, m_gather_weights, m_loop_end, m_loop_start, m_looping, m_on_end, m_repeat, m_repeat_length, m_repeat_start, m_structure, MayaFlux::Kakshya::ContainerDataStructure::organization, out, rate, stop(), and stream.

Referenced by process().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: