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 776 of file BufferPipeline.cpp.

777{
778 auto& promise = co_await Kriya::GetAudioPromise {};
779
780 if (m_operations.empty()) {
781 co_return;
782 }
783
785 uint32_t cycles_executed = 0;
786
787 while ((max_cycles == 0 || cycles_executed < max_cycles) && (m_continuous_execution || cycles_executed < max_cycles)) {
788
789 if (promise.should_terminate) {
790 break;
791 }
792
795 }
796
797 for (auto& state : m_data_states) {
798 if (state != DataState::EMPTY) {
799 state = DataState::EMPTY;
800 }
801 }
802
804
805 // ═══════════════════════════════════════════════════════
806 // PHASE 1: CAPTURE - Execute all capture operations
807 // ═══════════════════════════════════════════════════════
808 for (size_t i = 0; i < m_operations.size(); ++i) {
809 auto& op = m_operations[i];
810
812 continue;
813 }
814
815 if (op.get_type() == BufferOperation::OpType::CONDITION) {
816 if (!op.m_condition || !op.m_condition(m_current_cycle)) {
817 continue;
818 }
819 }
820
821 if (m_current_cycle % op.m_cycle_interval != 0) {
822 continue;
823 }
824
825 uint32_t op_iterations = 1;
826 if (op.get_type() == BufferOperation::OpType::CAPTURE) {
827 op_iterations = op.m_capture.get_cycle_count();
828 }
829
830 for (uint32_t iter = 0; iter < op_iterations; ++iter) {
833 co_await BufferDelay { 1 };
834 } else if (m_capture_timing == Vruta::DelayContext::SAMPLE_BASED && samples_per_operation > 0) {
835 co_await SampleDelay { samples_per_operation };
836 }
837 }
838
840 }
841
842 // ═══════════════════════════════════════════════════════
843 // PHASE 2: PROCESS - Execute all processing operations
844 // ═══════════════════════════════════════════════════════
845
846 for (size_t i = 0; i < m_operations.size(); ++i) {
847 auto& op = m_operations[i];
848
850 continue;
851 }
852
854 continue;
855 }
856
857 if (op.get_type() == BufferOperation::OpType::CONDITION) {
858 if (!op.m_condition || !op.m_condition(m_current_cycle)) {
859 continue;
860 }
861 }
862
863 if (m_current_cycle % op.m_cycle_interval != 0) {
864 continue;
865 }
866
869
871 co_await BufferDelay { 1 };
872 } else if (m_process_timing == Vruta::DelayContext::SAMPLE_BASED && samples_per_operation > 0) {
873 co_await SampleDelay { samples_per_operation };
874 }
875 }
876
877 // ═══════════════════════════════════════════════════════
878 // Handle branches (if any)
879 // ═══════════════════════════════════════════════════════
880 std::vector<std::shared_ptr<Vruta::SoundRoutine>> current_cycle_sync_tasks;
881
882 for (auto& branch : m_branches) {
883 if (branch.condition(m_current_cycle)) {
884 auto task = dispatch_branch_async(branch, m_current_cycle);
885
886 if (branch.synchronous && task) {
887 current_cycle_sync_tasks.push_back(task);
888 }
889 }
890 }
891
892 if (!current_cycle_sync_tasks.empty()) {
893 bool any_active = true;
894 while (any_active) {
895 any_active = false;
896
897 for (auto& task : current_cycle_sync_tasks) {
898 if (task && task->is_active()) {
899 any_active = true;
900 break;
901 }
902 }
903
904 if (any_active) {
906 co_await BufferDelay { 1 };
907 } else {
908 co_await SampleDelay { 1 };
909 }
910 }
911 }
912 }
913
915
918 }
919
921
923 cycles_executed++;
924 }
925
926 if (m_on_complete)
928}
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: