14 error<std::invalid_argument>(
16 std::source_location::current(),
17 "AudioContextProcessor: null context factory");
24 slot.context = factory();
26 error<std::invalid_argument>(
28 std::source_location::current(),
29 "AudioContextProcessor: factory returned a null context");
41 if (!std::dynamic_pointer_cast<AudioBuffer>(buffer)) {
43 "AudioContextProcessor can only attach to an AudioBuffer");
54 return std::dynamic_pointer_cast<AudioBuffer>(buffer) !=
nullptr;
64 foundry.wait_for_fence(slot.fence);
74 slot.
context->stage_words(0, samples);
75 slot.
context->set_output_size(0, samples.size() *
sizeof(uint64_t));
83 "AudioContextProcessor dispatch {} did not run", sequence);
89 auto audio = std::dynamic_pointer_cast<AudioBuffer>(buffer);
92 "AudioContextProcessor received a non-audio buffer");
96 auto& samples = audio->get_data();
97 if (samples.empty()) {
101 const uint64_t sequence =
m_next++;
103 const bool due = sequence >=
depth;
104 const uint64_t expected = due ? sequence -
depth : 0;
107 std::vector<double> delivered;
112 const auto result = slot.context->collect_result();
114 if (due && slot.sequence == expected) {
115 delivered = slot.context->decode_primary(result);
123 submit(slot, sequence, samples);
126 if (delivered.empty()) {
132 "AudioContextProcessor block {} was not complete, output is silent until results arrive in time", expected);
141 const size_t copied = std::min(samples.size(), delivered.size());
142 std::copy_n(delivered.begin(), copied, samples.begin());
143 std::fill(samples.begin() +
static_cast<std::ptrdiff_t
>(copied), samples.end(), 0.0);
#define MF_ERROR(comp, ctx,...)
#define MF_RT_WARN(comp, ctx,...)
#define MF_RT_ERROR(comp, ctx,...)
Runs a shader on doubles carried as two 32-bit words, with no fp64 on the device.
std::function< void(Yantra::WordPairExecutionContext &, std::span< const double >, uint64_t)> StageFunction
Fills a context for one job from the child's samples and the call's sequence number.
void processing_function(const std::shared_ptr< Buffer > &buffer) override
The core processing function that must be implemented by derived classes.
void on_detach(const std::shared_ptr< Buffer > &buffer) override
Called when this processor is detached from a buffer.
void submit(Slot &slot, uint64_t sequence, std::span< const double > samples)
std::function< std::shared_ptr< Yantra::WordPairExecutionContext >()> ContextFactory
bool is_compatible_with(const std::shared_ptr< Buffer > &buffer) const override
Checks if this processor can handle the specified buffer type.
void on_attach(const std::shared_ptr< Buffer > &buffer) override
Called when this processor is attached to a buffer.
~AudioContextProcessor() override
std::vector< Slot > m_slots
AudioContextProcessor(const ContextFactory &factory, uint32_t depth=2, StageFunction stage={})
ProcessingToken m_processing_token
@ AUDIO_PARALLEL
High-performance audio processing with GPU acceleration.
@ BufferProcessing
Buffer processing (Buffers::BufferManager, processing chains).
@ Init
Engine/subsystem initialization.
@ Buffers
Buffers, Managers, processors and processing chains.
constexpr FenceID INVALID_FENCE
MAYAFLUX_API ShaderFoundry & get_shader_foundry()
Get the global shader compiler instance.
Portal::Graphics::FenceID fence
std::shared_ptr< Yantra::WordPairExecutionContext > context
Input/Output container for computation pipeline data flow with structure preservation.