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

◆ execute_phased()

Vruta::SoundRoutine MayaFlux::Kriya::BufferPipeline::execute_phased ( uint64_t  max_cycles,
uint64_t  samples_per_operation 
)
private

Definition at line 733 of file BufferPipeline.cpp.

734{
735 auto& promise = co_await Kriya::GetAudioPromise {};
736
737 if (m_operations.empty()) {
738 co_return;
739 }
740
742 uint32_t cycles_executed = 0;
743
744 while ((max_cycles == 0 || cycles_executed < max_cycles) && (m_continuous_execution || cycles_executed < max_cycles)) {
745
746 if (promise.should_terminate) {
747 break;
748 }
749
752 }
753
754 for (auto& state : m_data_states) {
755 if (state != DataState::EMPTY) {
756 state = DataState::EMPTY;
757 }
758 }
759
761
762 // ═══════════════════════════════════════════════════════
763 // PHASE 1: CAPTURE - Execute all capture operations
764 // ═══════════════════════════════════════════════════════
765 for (size_t i = 0; i < m_operations.size(); ++i) {
766 auto& op = m_operations[i];
767
769 continue;
770 }
771
772 if (op.get_type() == BufferOperation::OpType::CONDITION) {
773 if (!op.m_condition || !op.m_condition(m_current_cycle)) {
774 continue;
775 }
776 }
777
778 if (m_current_cycle % op.m_cycle_interval != 0) {
779 continue;
780 }
781
782 uint32_t op_iterations = 1;
783 if (op.get_type() == BufferOperation::OpType::CAPTURE) {
784 op_iterations = op.m_capture.get_cycle_count();
785 }
786
787 for (uint32_t iter = 0; iter < op_iterations; ++iter) {
790 co_await BufferDelay { 1 };
791 } else if (m_capture_timing == Vruta::DelayContext::SAMPLE_BASED && samples_per_operation > 0) {
792 co_await SampleDelay { samples_per_operation };
793 }
794 }
795
797 }
798
799 // ═══════════════════════════════════════════════════════
800 // PHASE 2: PROCESS - Execute all processing operations
801 // ═══════════════════════════════════════════════════════
802
803 for (size_t i = 0; i < m_operations.size(); ++i) {
804 auto& op = m_operations[i];
805
807 continue;
808 }
809
811 continue;
812 }
813
814 if (op.get_type() == BufferOperation::OpType::CONDITION) {
815 if (!op.m_condition || !op.m_condition(m_current_cycle)) {
816 continue;
817 }
818 }
819
820 if (m_current_cycle % op.m_cycle_interval != 0) {
821 continue;
822 }
823
826
828 co_await BufferDelay { 1 };
829 } else if (m_process_timing == Vruta::DelayContext::SAMPLE_BASED && samples_per_operation > 0) {
830 co_await SampleDelay { samples_per_operation };
831 }
832 }
833
834 // ═══════════════════════════════════════════════════════
835 // Handle branches (if any)
836 // ═══════════════════════════════════════════════════════
837 std::vector<std::shared_ptr<Vruta::SoundRoutine>> current_cycle_sync_tasks;
838
839 for (auto& branch : m_branches) {
840 if (branch.condition(m_current_cycle)) {
841 auto task = dispatch_branch_async(branch, m_current_cycle);
842
843 if (branch.synchronous && task) {
844 current_cycle_sync_tasks.push_back(task);
845 }
846 }
847 }
848
849 if (!current_cycle_sync_tasks.empty()) {
850 bool any_active = true;
851 while (any_active) {
852 any_active = false;
853
854 for (auto& task : current_cycle_sync_tasks) {
855 if (task && task->is_active()) {
856 any_active = true;
857 break;
858 }
859 }
860
861 if (any_active) {
863 co_await BufferDelay { 1 };
864 } else {
865 co_await SampleDelay { 1 };
866 }
867 }
868 }
869 }
870
872
875 }
876
878
880 cycles_executed++;
881 }
882}
static bool is_capture_phase_operation(const BufferOperation &op)
@ CONDITION
Conditional operation for branching logic.
@ CAPTURE
Capture data from source buffer using BufferCapture strategy.
static bool is_process_phase_operation(const BufferOperation &op)
@ READY
Data ready for processing.
void process_operation(BufferOperation &op, uint64_t cycle)
std::vector< BranchInfo > m_branches
std::vector< BufferOperation > m_operations
std::vector< DataState > m_data_states
std::function< void(uint32_t)> m_cycle_end_callback
std::function< void(uint32_t)> m_cycle_start_callback
std::shared_ptr< Vruta::SoundRoutine > dispatch_branch_async(BranchInfo &branch, uint64_t cycle)
GetPromiseBase< Vruta::audio_promise > GetAudioPromise
Audio domain promise accessor.
Definition Awaiters.hpp:231
@ SAMPLE_BASED
Sample-accurate delay (audio domain)
@ BUFFER_BASED
Buffer-cycle delay (audio hardware boundary)

References MayaFlux::Vruta::BUFFER_BASED, MayaFlux::Kriya::BufferOperation::CAPTURE, cleanup_completed_branches(), cleanup_expired_data(), MayaFlux::Kriya::BufferOperation::CONDITION, CONSUMED, dispatch_branch_async(), EMPTY, MayaFlux::Kriya::BufferOperation::is_capture_phase_operation(), MayaFlux::Kriya::BufferOperation::is_process_phase_operation(), m_branches, m_capture_timing, m_continuous_execution, m_current_cycle, m_cycle_end_callback, m_cycle_start_callback, m_data_states, m_operations, m_process_timing, process_operation(), READY, reset_accumulated_data(), and MayaFlux::Vruta::SAMPLE_BASED.

Referenced by execute_internal(), execute_parallel(), and execute_reactive().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: