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

◆ route_buffer_to_channel()

void MayaFlux::Buffers::BufferSupplyMixing::route_buffer_to_channel ( const std::shared_ptr< AudioBuffer > &  buffer,
uint32_t  target_channel,
uint32_t  fade_cycles,
ProcessingToken  token 
)

Routes a buffer's processing from one channel to another with fade.

Parameters
bufferBuffer to route
target_channelDestination channel
fade_cyclesNumber of processing cycles to fade over
tokenProcessing domain

Transitions the buffer's channel_id from its current channel to the target channel with smooth crossfade. During transition, buffer continues processing in its original channel while fading in via supply to the target channel.

Definition at line 186 of file BufferSupplyMixing.cpp.

191{
192 if (!buffer) {
194 "BufferSupplyMixing: Invalid buffer for routing");
195 return;
196 }
197
198 uint32_t current_channel = buffer->get_channel_id();
199
200 if (current_channel == target_channel) {
202 "BufferSupplyMixing: Buffer already on target channel {}", target_channel);
203 return;
204 }
205
206 if (!m_unit_manager.has_audio_unit(token)) {
208 "BufferSupplyMixing: Invalid token for routing");
209 return;
210 }
211
212 auto& unit = m_unit_manager.get_audio_unit_mutable(token);
213 if (target_channel >= unit.channel_count) {
215 "BufferSupplyMixing: Target channel {} out of range", target_channel);
216 return;
217 }
218
219 uint32_t fade_blocks = std::max(1U, fade_cycles);
220
221 BufferRoutingState state;
222 state.from_channel = current_channel;
223 state.to_channel = target_channel;
224 state.fade_cycles = fade_blocks;
225 state.from_amount = 1.0;
226 state.to_amount = 0.0;
227 state.cycles_elapsed = 0;
228 state.phase = BufferRoutingState::ACTIVE;
229
230 buffer->get_routing_state() = state;
231
232 supply_audio_buffer_to(buffer, token, target_channel, 0.0);
233}
#define MF_ERROR(comp, ctx,...)
#define MF_WARN(comp, ctx,...)
bool supply_audio_buffer_to(const std::shared_ptr< AudioBuffer > &buffer, ProcessingToken token, uint32_t channel, double mix=1.0)
Supplies an external audio buffer to a specific token and channel.
TokenUnitManager & m_unit_manager
Reference to the token/unit manager.
bool has_audio_unit(ProcessingToken token) const
Checks if an audio unit exists for the given token.
RootAudioUnit & get_audio_unit_mutable(ProcessingToken token)
Gets an existing audio unit without creating if missing (mutable)
@ BufferManagement
Buffer Management (Buffers::BufferManager, creating buffers)
@ Buffers
Buffers, Managers, processors and processing chains.

References MayaFlux::Buffers::BufferRoutingState::ACTIVE, MayaFlux::Journal::BufferManagement, MayaFlux::Journal::Buffers, MayaFlux::Buffers::BufferRoutingState::cycles_elapsed, MayaFlux::Buffers::BufferRoutingState::fade_cycles, MayaFlux::Buffers::BufferRoutingState::from_amount, MayaFlux::Buffers::BufferRoutingState::from_channel, MayaFlux::Buffers::TokenUnitManager::get_audio_unit_mutable(), MayaFlux::Buffers::TokenUnitManager::has_audio_unit(), m_unit_manager, MF_ERROR, MF_WARN, supply_audio_buffer_to(), MayaFlux::Buffers::BufferRoutingState::to_amount, and MayaFlux::Buffers::BufferRoutingState::to_channel.

+ Here is the call graph for this function: