MayaFlux 0.4.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 790 of file BufferPipeline.cpp.

791{
792 auto& promise = co_await Kriya::GetAudioPromise {};
793
794 if (m_operations.empty()) {
795 co_return;
796 }
797
799 uint32_t cycles_executed = 0;
800
801 while ((max_cycles == 0 || cycles_executed < max_cycles) && (m_continuous_execution || cycles_executed < max_cycles)) {
802
803 if (promise.should_terminate) {
804 break;
805 }
806
809 }
810
811 for (auto& state : m_data_states) {
812 if (state != DataState::EMPTY) {
813 state = DataState::EMPTY;
814 }
815 }
816
818
819 // ═══════════════════════════════════════════════════════
820 // PHASE 1: CAPTURE - Execute all capture operations
821 // ═══════════════════════════════════════════════════════
822 for (size_t i = 0; i < m_operations.size(); ++i) {
823 auto& op = m_operations[i];
824
826 continue;
827 }
828
829 if (op.get_type() == BufferOperation::OpType::CONDITION) {
830 if (!op.m_condition || !op.m_condition(m_current_cycle)) {
831 continue;
832 }
833 }
834
835 if (m_current_cycle % op.m_cycle_interval != 0) {
836 continue;
837 }
838
839 uint32_t op_iterations = 1;
840 if (op.get_type() == BufferOperation::OpType::CAPTURE) {
841 op_iterations = op.m_capture.get_cycle_count();
842 }
843
844 for (uint32_t iter = 0; iter < op_iterations; ++iter) {
847 co_await BufferDelay { 1 };
848 } else if (m_capture_timing == Vruta::DelayContext::SAMPLE_BASED && samples_per_operation > 0) {
849 co_await SampleDelay { samples_per_operation };
850 }
851 }
852
854 }
855
856 // ═══════════════════════════════════════════════════════
857 // PHASE 2: PROCESS - Execute all processing operations
858 // ═══════════════════════════════════════════════════════
859
860 for (size_t i = 0; i < m_operations.size(); ++i) {
861 auto& op = m_operations[i];
862
864 continue;
865 }
866
868 continue;
869 }
870
871 if (op.get_type() == BufferOperation::OpType::CONDITION) {
872 if (!op.m_condition || !op.m_condition(m_current_cycle)) {
873 continue;
874 }
875 }
876
877 if (m_current_cycle % op.m_cycle_interval != 0) {
878 continue;
879 }
880
883
885 co_await BufferDelay { 1 };
886 } else if (m_process_timing == Vruta::DelayContext::SAMPLE_BASED && samples_per_operation > 0) {
887 co_await SampleDelay { samples_per_operation };
888 }
889 }
890
891 // ═══════════════════════════════════════════════════════
892 // Handle branches (if any)
893 // ═══════════════════════════════════════════════════════
894 std::vector<std::shared_ptr<Vruta::SoundRoutine>> current_cycle_sync_tasks;
895
896 for (auto& branch : m_branches) {
897 if (branch.condition(m_current_cycle)) {
898 auto task = dispatch_branch_async(branch, m_current_cycle);
899
900 if (branch.synchronous && task) {
901 current_cycle_sync_tasks.push_back(task);
902 }
903 }
904 }
905
906 if (!current_cycle_sync_tasks.empty()) {
907 bool any_active = true;
908 while (any_active) {
909 any_active = false;
910
911 for (auto& task : current_cycle_sync_tasks) {
912 if (task && task->is_active()) {
913 any_active = true;
914 break;
915 }
916 }
917
918 if (any_active) {
920 co_await BufferDelay { 1 };
921 } else {
922 co_await SampleDelay { 1 };
923 }
924 }
925 }
926 }
927
929
932 }
933
935
937 cycles_executed++;
938 }
939
940 if (m_on_complete)
942}
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::function< void()> m_on_complete
std::shared_ptr< Vruta::SoundRoutine > dispatch_branch_async(BranchInfo &branch, uint64_t cycle)
GetPromiseBase< Vruta::audio_promise > GetAudioPromise
Audio domain promise accessor.
@ 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_on_complete, 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: