MayaFlux 0.1.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
ContiguousAccessProcessor.hpp
Go to the documentation of this file.
1#pragma once
2
4
6
8
9/**
10 * @class ContiguousAccessProcessor
11 * @brief Data Processor for efficient, sequential access to N-dimensional data containers.
12 *
13 * ContiguousAccessProcessor is the default processor for streaming, reading, and processing
14 * N-dimensional data in a linear, memory-efficient manner. It is designed for digital-first,
15 * data-driven workflows and supports:
16 * - Efficient sequential access to multi-dimensional data (audio, images, tensors, etc.)
17 * - Both row-major and column-major memory layouts
18 * - Automatic or manual advancement of read position for streaming or block-based processing
19 * - Looping and region-based access for playback, streaming, or repeated analysis
20 * - Flexible output buffer sizing and dimension selection for custom workflows
21 *
22 * This processor is foundational for scenarios such as:
23 * - Real-time audio or signal streaming
24 * - Batch or block-based data processing
25 * - Efficient extraction of contiguous regions for machine learning or DSP
26 * - Integration with digital-first nodes, routines, and buffer systems
27 *
28 * Unlike analog-inspired processors, ContiguousAccessProcessor is unconstrained by
29 * legacy metaphors and is optimized for modern, data-centric applications.
30 */
31namespace MayaFlux::Kakshya {
32
33class MAYAFLUX_API ContiguousAccessProcessor : public DataProcessor {
34public:
36 ~ContiguousAccessProcessor() override = default;
37
38 /**
39 * @brief Attach the processor to a signal source container.
40 * Initializes dimension metadata, memory layout, and prepares for processing.
41 * @param container The SignalSourceContainer to attach to.
42 */
43 void on_attach(std::shared_ptr<SignalSourceContainer> container) override;
44
45 /**
46 * @brief Detach the processor from its container.
47 * Cleans up internal state and metadata.
48 * @param container The SignalSourceContainer to detach from.
49 */
50 void on_detach(std::shared_ptr<SignalSourceContainer> container) override;
51
52 /**
53 * @brief Process the current region or block of data.
54 * Advances the read position if auto-advance is enabled.
55 * @param container The SignalSourceContainer to process.
56 */
57 void process(std::shared_ptr<SignalSourceContainer> container) override;
58
59 /**
60 * @brief Query if the processor is currently performing processing.
61 * @return true if processing is in progress, false otherwise.
62 */
63 bool is_processing() const override { return m_is_processing.load(); }
64
65 /**
66 * @brief Set the output buffer size (shape) for each processing call.
67 * @param shape Vector specifying the size in each dimension.
68 */
69 void set_output_size(const std::vector<uint64_t>& shape);
70
71 /**
72 * @brief Enable or disable automatic advancement of the read position after each process call.
73 * @param enable true to auto-advance, false for manual control.
74 */
75 void set_auto_advance(bool enable) { m_auto_advance = enable; }
76
77 /**
78 * @brief Set the current read position (N-dimensional coordinates).
79 * @param new_position New position vector.
80 */
81 inline void set_current_position(const std::vector<uint64_t>& new_position)
82 {
83 m_current_position = new_position;
84 }
85
86private:
87 // Processing state
88 std::atomic<bool> m_is_processing { false };
89 bool m_prepared {};
90 bool m_auto_advance { true };
91
92 // Container reference
93 std::weak_ptr<SignalSourceContainer> m_source_container_weak;
94
95 // Dimension information
97
98 // Position tracking
99 std::vector<uint64_t> m_current_position;
100 std::vector<uint64_t> m_output_shape;
101
102 // Loop configuration
103 bool m_looping_enabled {};
105
106 // Metadata
107 uint64_t m_total_elements {};
108 std::chrono::steady_clock::time_point m_last_process_time;
109
110 /**
111 * @brief Store dimension and layout metadata from the container.
112 * @param container The SignalSourceContainer to query.
113 */
114 void store_metadata(const std::shared_ptr<SignalSourceContainer>& container);
115
116 /**
117 * @brief Validate the container's structure and output configuration.
118 * Throws if configuration is invalid.
119 */
120 void validate();
121};
122
123} // namespace MayaFlux::Kakshya
bool is_processing() const override
Query if the processor is currently performing processing.
std::chrono::steady_clock::time_point m_last_process_time
void set_current_position(const std::vector< uint64_t > &new_position)
Set the current read position (N-dimensional coordinates).
void set_auto_advance(bool enable)
Enable or disable automatic advancement of the read position after each process call.
std::weak_ptr< SignalSourceContainer > m_source_container_weak
Interface for processing data within SignalSourceContainer objects.
Container structure for consistent dimension ordering.
Represents a point or span in N-dimensional space.
Definition Region.hpp:67