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

◆ process()

void MayaFlux::Kakshya::CursorAccessProcessor::process ( const std::shared_ptr< SignalSourceContainer > &  container)
overridevirtual

Extract one block of frames into container processed_data[0].

If inactive, fills processed_data[0] with silence and returns. Advances m_cursor by m_frames_per_block after each active read. On reaching the loop end, wraps to m_loop_start if looping, otherwise deactivates and fires m_on_end if set.

Parameters
containerMust be the DynamicSoundStream passed to on_attach.

Implements MayaFlux::Kakshya::DataProcessor.

Definition at line 46 of file CursorAccessProcessor.cpp.

47{
48 m_is_processing.store(true, std::memory_order_relaxed);
49
50 auto stream = std::dynamic_pointer_cast<DynamicSoundStream>(container);
51 if (!stream) {
53 "CursorAccessProcessor requires a DynamicSoundStream");
54 m_is_processing.store(false, std::memory_order_relaxed);
55 return;
56 }
57
58 auto& pd = stream->get_dynamic_data(m_slot_index);
59
60 if (!m_active) {
61 const uint64_t num_channels = m_structure.get_channel_count();
63 pd.resize(1);
64 std::get<std::vector<double>>(pd[0]).assign(m_frames_per_block * num_channels, 0.0);
65 } else {
66 pd.resize(num_channels);
67 for (auto& ch : pd)
68 std::get<std::vector<double>>(ch).assign(m_frames_per_block, 0.0);
69 }
70 m_is_processing.store(false, std::memory_order_relaxed);
71 return;
72 }
73
74 const uint64_t frame = m_cursor.empty() ? 0 : m_cursor[0];
75
76 const uint64_t total_frames = m_structure.get_samples_count_per_channel();
77 const uint64_t read_end = std::min(frame + m_frames_per_block - 1, total_frames - 1);
78
79 const Region region {
80 std::vector<uint64_t> { frame, 0 },
81 std::vector<uint64_t> { read_end, m_structure.get_channel_count() - 1 }
82 };
83
84 auto region_data = container->get_region_data(region);
85
87 pd.resize(1);
88 if (!region_data.empty())
89 safe_copy_data_variant(region_data[0], pd[0]);
90 } else {
91 const uint64_t ch_count = std::min(
92 static_cast<uint64_t>(region_data.size()),
94 pd.resize(ch_count);
95 for (size_t c = 0; c < ch_count; ++c)
96 safe_copy_data_variant(region_data[c], pd[c]);
97 }
98
99 const double raw_advance = static_cast<double>(m_frames_per_block) * m_speed + m_speed_remainder;
100 const auto int_advance = static_cast<uint64_t>(raw_advance);
101 m_speed_remainder = raw_advance - static_cast<double>(int_advance);
102
103 const uint64_t next = frame + int_advance;
104 const uint64_t loop_end = m_loop_end;
105
106 if (next >= loop_end) {
107 if (m_looping) {
108 if (m_loop_count > 0) {
110 if (m_loops_remaining == 0) {
111 m_active = false;
112 m_speed_remainder = 0.0;
113 m_cursor.assign(m_cursor.size(), m_loop_start);
114 if (m_on_end)
115 m_on_end();
116 m_is_processing.store(false, std::memory_order_relaxed);
117 return;
118 }
119 }
120 m_speed_remainder = 0.0;
121 m_cursor.assign(m_cursor.size(), m_loop_start);
122 } else {
123 m_active = false;
124 m_speed_remainder = 0.0;
125 m_cursor.assign(m_cursor.size(), m_loop_start);
126 if (m_on_end)
127 m_on_end();
128 }
129 } else {
130 m_cursor.assign(m_cursor.size(), next);
131 }
132
133 m_is_processing.store(false, std::memory_order_relaxed);
134}
#define MF_RT_ERROR(comp, ctx,...)
@ ContainerProcessing
Container operations (Kakshya - file/stream/region processing)
@ Kakshya
Containers[Signalsource, Stream, File], Regions, DataProcessors.
@ INTERLEAVED
Single DataVariant with interleaved data (LRLRLR for stereo)
void safe_copy_data_variant(const DataVariant &input, DataVariant &output)
Safely copy data from a DataVariant to another DataVariant, handling type conversion.
Definition DataUtils.cpp:34
static uint64_t get_channel_count(const std::vector< DataDimension > &dimensions)
Extract channel count from dimensions.
static uint64_t get_samples_count_per_channel(const std::vector< DataDimension > &dimensions)
Get samples per channel (time dimension only).

References MayaFlux::Journal::ContainerProcessing, MayaFlux::Kakshya::ContainerDataStructure::get_channel_count(), MayaFlux::Kakshya::ContainerDataStructure::get_samples_count_per_channel(), MayaFlux::Kakshya::INTERLEAVED, MayaFlux::Journal::Kakshya, loop_end(), m_active, m_cursor, m_frames_per_block, m_is_processing, m_loop_count, m_loop_end, m_loop_start, m_looping, m_loops_remaining, m_on_end, m_slot_index, m_speed, m_speed_remainder, m_structure, MF_RT_ERROR, MayaFlux::Kakshya::ContainerDataStructure::organization, and MayaFlux::Kakshya::safe_copy_data_variant().

+ Here is the call graph for this function: