MayaFlux 1.0.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 48 of file CursorAccessProcessor.cpp.

49{
50 m_is_processing.store(true, std::memory_order_relaxed);
51
52 auto stream = std::dynamic_pointer_cast<DynamicSoundStream>(container);
53 if (!stream) {
55 "CursorAccessProcessor requires a DynamicSoundStream");
56 m_is_processing.store(false, std::memory_order_relaxed);
57 return;
58 }
59
60 auto& pd = stream->get_dynamic_data(m_slot_index);
61
62 if (!m_active) {
63 const uint64_t num_channels = m_structure.get_channel_count();
65 pd.resize(1);
66 std::get<std::vector<double>>(pd[0]).assign(m_frames_per_block * num_channels, 0.0);
67 } else {
68 pd.resize(num_channels);
69 for (auto& ch : pd)
70 std::get<std::vector<double>>(ch).assign(m_frames_per_block, 0.0);
71 }
72 m_is_processing.store(false, std::memory_order_relaxed);
73 return;
74 }
75
76 if (m_time_map && m_time_map->fn) {
78 m_is_processing.store(false, std::memory_order_relaxed);
79 return;
80 }
81
82 const uint64_t frame = m_cursor.empty() ? 0 : m_cursor[0];
83
84 const uint64_t total_frames = m_structure.get_samples_count_per_channel();
85 const uint64_t read_end = std::min(frame + m_frames_per_block - 1, total_frames - 1);
86
87 const Region region {
88 std::vector<uint64_t> { frame, 0 },
89 std::vector<uint64_t> { read_end, m_structure.get_channel_count() - 1 }
90 };
91
92 auto region_data = container->get_region_data(region);
93
95 pd.resize(1);
96 if (!region_data.empty())
97 safe_copy_data_variant(region_data[0], pd[0]);
98 } else {
99 const uint64_t ch_count = std::min(
100 static_cast<uint64_t>(region_data.size()),
102 pd.resize(ch_count);
103 for (size_t c = 0; c < ch_count; ++c)
104 safe_copy_data_variant(region_data[c], pd[c]);
105 }
106
107 const double raw_advance = static_cast<double>(m_frames_per_block) * m_speed + m_speed_remainder;
108 const auto int_advance = static_cast<uint64_t>(raw_advance);
109 m_speed_remainder = raw_advance - static_cast<double>(int_advance);
110
111 const uint64_t next = frame + int_advance;
112 const uint64_t loop_end = m_loop_end;
113
114 if (next >= loop_end) {
115 if (m_looping) {
116 if (m_loop_count > 0) {
118 if (m_loops_remaining == 0) {
119 m_active = false;
120 m_speed_remainder = 0.0;
121 m_cursor.assign(m_cursor.size(), m_loop_start);
122 if (m_on_end)
123 m_on_end();
124 m_is_processing.store(false, std::memory_order_relaxed);
125 return;
126 }
127 }
128 m_speed_remainder = 0.0;
129 m_cursor.assign(m_cursor.size(), m_loop_start);
130 } else {
131 m_active = false;
132 m_speed_remainder = 0.0;
133 m_cursor.assign(m_cursor.size(), m_loop_start);
134 if (m_on_end)
135 m_on_end();
136 }
137 } else {
138 m_cursor.assign(m_cursor.size(), next);
139 }
140
141 m_is_processing.store(false, std::memory_order_relaxed);
142}
#define MF_RT_ERROR(comp, ctx,...)
Core::GlobalStreamInfo stream
Definition Config.cpp:40
std::shared_ptr< const Kinesis::TimeMap > m_time_map
void process_mapped(DynamicSoundStream &stream, std::vector< DataVariant > &pd)
@ ContainerProcessing
Container operations (Kakshya - file/stream/region processing)
@ Kakshya
Containers[Signalsource, Stream, File], Regions, DataProcessors.
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:36
@ INTERLEAVED
Single DataVariant with interleaved data (LRLRLR for stereo)
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, m_time_map, MF_RT_ERROR, MayaFlux::Kakshya::ContainerDataStructure::organization, process_mapped(), MayaFlux::Kakshya::safe_copy_data_variant(), and stream.

+ Here is the call graph for this function: