MayaFlux 0.1.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
BufferSupplyMixing.hpp
Go to the documentation of this file.
1#pragma once
2
4
5namespace MayaFlux::Buffers {
6
7class AudioBuffer;
8class TokenUnitManager;
9class BufferAccessControl;
10
11/**
12 * @class BufferSupplyMixing
13 * @brief External buffer supply, mixing, and interleaved data I/O
14 *
15 * Manages operations for supplying external buffers to channels, mixing buffers,
16 * and converting between interleaved and channel-separated formats. This enables
17 * advanced routing patterns where the same buffer feeds multiple channels,
18 * or data is imported/exported in different formats.
19 *
20 * Design Principles:
21 * - Token-aware: Routes operations to appropriate tokens
22 * - Format-agnostic: Handles both channel-separated and interleaved data
23 * - Mixing coordination: Uses MixProcessor for proper signal combining
24 * - Single responsibility: Only handles supply/mixing/format operations
25 *
26 * This class encapsulates all buffer supply and data I/O logic.
27 */
28class MAYAFLUX_API BufferSupplyMixing {
29public:
30 /**
31 * @brief Creates a new supply/mixing control handler
32 * @param unit_manager Reference to the TokenUnitManager
33 * @param access_control Reference to the BufferAccessControl
34 */
35 BufferSupplyMixing(TokenUnitManager& unit_manager, BufferAccessControl& access_control);
36
38
39 // =========================================================================
40 // Buffer Supply and Mixing
41 // =========================================================================
42
43 /**
44 * @brief Supplies an external audio buffer to a specific token and channel
45 * @param buffer Buffer to supply
46 * @param token Processing domain
47 * @param channel Channel index
48 * @param mix Mix level (default: 1.0)
49 * @return True if the buffer was successfully supplied, false otherwise
50 *
51 * The buffer data is added, mixed, and normalized at the end of the processing
52 * chain of the channel's root buffer, but before final processing. This is
53 * useful when one AudioBuffer needs to be supplied to multiple channels.
54 */
55 bool supply_audio_buffer_to(
56 const std::shared_ptr<AudioBuffer>& buffer,
58 uint32_t channel,
59 double mix = 1.0);
60
61 /**
62 * @brief Removes a previously supplied buffer from a token and channel
63 * @param buffer Buffer to remove
64 * @param token Processing domain
65 * @param channel Channel index
66 * @return True if the buffer was successfully removed, false otherwise
67 *
68 * Cleans up the mixing relationship between the supplied buffer and the target channel.
69 */
70 bool remove_supplied_audio_buffer(
71 const std::shared_ptr<AudioBuffer>& buffer,
73 uint32_t channel);
74
75 // =========================================================================
76 // Interleaved Data I/O
77 // =========================================================================
78
79 /**
80 * @brief Fills audio token channels from interleaved source data
81 * @param interleaved_data Source interleaved data buffer
82 * @param num_frames Number of frames to process
83 * @param token Processing domain
84 * @param num_channels Number of channels in the interleaved data
85 *
86 * Takes interleaved data (like typical audio file format or hardware I/O)
87 * and distributes it to the token's channels.
88 */
89 void fill_audio_from_interleaved(
90 const double* interleaved_data,
91 uint32_t num_frames,
93 uint32_t num_channels);
94
95 /**
96 * @brief Fills interleaved buffer from audio token channels
97 * @param interleaved_data Target interleaved data buffer
98 * @param num_frames Number of frames to process
99 * @param token Processing domain
100 * @param num_channels Number of channels to interleave
101 *
102 * Takes channel-separated data from the token and interleaves it into
103 * a single buffer (like typical audio file format or hardware I/O).
104 */
105 void fill_audio_interleaved(
106 double* interleaved_data,
107 uint32_t num_frames,
109 uint32_t num_channels) const;
110
111 // =========================================================================
112 // Buffer Cloning
113 // =========================================================================
114
115 /**
116 * @brief Clones an audio buffer for each channel in the specified list
117 * @param buffer Buffer to clone
118 * @param channels Vector of channel indices to clone for
119 * @param token Processing domain
120 *
121 * Creates a new buffer for each specified channel, copying the structure
122 * but maintaining independent data. Useful for multi-channel processing
123 * where each channel needs its own processing chain.
124 */
125 std::vector<std::shared_ptr<AudioBuffer>> clone_audio_buffer_for_channels(
126 const std::shared_ptr<AudioBuffer>& buffer,
127 const std::vector<uint32_t>& channels,
129
130private:
131 /// Reference to the token/unit manager
133
134 /// Reference to the buffer access control
136};
137
138} // namespace MayaFlux::Buffers
static MayaFlux::Nodes::ProcessingToken token
Definition Timers.cpp:8
Token-aware buffer and unit access patterns.
TokenUnitManager & m_unit_manager
Reference to the token/unit manager.
BufferAccessControl & m_access_control
Reference to the buffer access control.
External buffer supply, mixing, and interleaved data I/O.
Token-scoped unit storage and lifecycle management.
ProcessingToken
Bitfield enum defining processing characteristics and backend requirements for buffer operations.