MayaFlux 0.1.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
StreamWriteProcessor.hpp
Go to the documentation of this file.
1#pragma once
2
4
5namespace MayaFlux::Kakshya {
6class DynamicSoundStream;
7}
8
9namespace MayaFlux::Buffers {
10
11/**
12 * @class StreamWriteProcessor
13 * @brief Channel-aware processor that writes AudioBuffer data to DynamicSoundStream containers.
14 *
15 * StreamWriteProcessor provides a bridge between the AudioBuffer processing system
16 * and DynamicSoundStream containers for real-time recording and data capture scenarios.
17 * It extracts audio data from buffers and streams it directly to the appropriate channel
18 * in the container with automatic capacity management and channel mapping.
19 *
20 * **Key Features:**
21 * - **Channel-Aware Writing**: Maps AudioBuffer channel ID to container channel
22 * - **Position Management**: Tracks write position per processor instance
23 * - **Automatic Capacity**: Leverages container's dynamic resizing for unlimited recording
24 * - **Circular Buffer Support**: Handles position wrapping for circular containers
25 * - **Real-time Safe**: Optimized for low-latency audio processing chains
26 * - **Thread-Safe**: Ensures safe concurrent access to container data
27 *
28 * **Use Cases:**
29 * - Multi-channel real-time audio recording
30 * - Capturing processed audio from node networks
31 * - Creating channel-specific delay lines and feedback systems
32 * - Building multi-track looping and overdub functionality
33 * - Streaming multi-channel audio to storage or network destinations
34 *
35 * **Channel Mapping:**
36 * Each AudioBuffer's channel_id corresponds directly to a channel in the target
37 * DynamicSoundStream. Buffers with channel IDs exceeding the container's channel
38 * count will be skipped with a warning.
39 *
40 * @note For real-time use cases, consider pre-allocating container capacity or
41 * enabling circular mode to avoid dynamic allocations during processing.
42 */
43class MAYAFLUX_API StreamWriteProcessor : public BufferProcessor {
44public:
45 /**
46 * @brief Construct processor with target DynamicSoundStream container.
47 * @param container Target container for writing audio data
48 * @param start_position Initial write position in frames (default: 0)
49 */
50 explicit StreamWriteProcessor(std::shared_ptr<Kakshya::DynamicSoundStream> container,
51 uint64_t start_position = 0)
52 : m_container(container)
53 , m_write_position(start_position)
54 {
55 }
56
57 /**
58 * @brief Write buffer audio data to the appropriate container channel.
59 * Extracts audio samples and streams them to the DynamicSoundStream channel
60 * corresponding to the AudioBuffer's channel ID.
61 * @param buffer AudioBuffer containing data to write
62 */
63 void processing_function(std::shared_ptr<Buffer> buffer) override;
64
65 /**
66 * @brief Get the target DynamicSoundStream container.
67 * @return Shared pointer to the container receiving audio data
68 */
69 [[nodiscard]] inline std::shared_ptr<Kakshya::DynamicSoundStream> get_container() const { return m_container; }
70
71 /**
72 * @brief Set the current write position in the container.
73 * @param position Frame position where next write will occur
74 */
75 inline void set_write_position(uint64_t position) { m_write_position = position; }
76
77 /**
78 * @brief Get the current write position in the container.
79 * @return Current frame position for writing
80 */
81 [[nodiscard]] inline uint64_t get_write_position() const { return m_write_position; }
82
83 /**
84 * @brief Reset write position to the beginning.
85 * Useful for starting new recording sessions or loop cycles.
86 */
87 inline void reset_position() { m_write_position = 0; }
88
89 /**
90 * @brief Set write position to a specific time offset.
91 * @param time_seconds Time offset in seconds from the beginning
92 */
93 void set_write_position_time(double time_seconds);
94
95 /**
96 * @brief Get current write position as time offset.
97 * @return Current write position in seconds from the beginning
98 */
99 [[nodiscard]] double get_write_position_time() const;
100
101private:
102 std::shared_ptr<Kakshya::DynamicSoundStream> m_container;
103 uint64_t m_write_position { 0 }; ///< Current write position in frames
104};
105
106} // namespace MayaFlux::Buffers
Central computational transformation interface for continuous buffer processing.
std::shared_ptr< Kakshya::DynamicSoundStream > m_container
std::shared_ptr< Kakshya::DynamicSoundStream > get_container() const
Get the target DynamicSoundStream container.
void set_write_position(uint64_t position)
Set the current write position in the container.
uint64_t get_write_position() const
Get the current write position in the container.
void reset_position()
Reset write position to the beginning.
StreamWriteProcessor(std::shared_ptr< Kakshya::DynamicSoundStream > container, uint64_t start_position=0)
Construct processor with target DynamicSoundStream container.
Channel-aware processor that writes AudioBuffer data to DynamicSoundStream containers.